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,
227 struct bdb_info *bdb = (struct bdb_info *) op->o_bd->be_private;
231 Debug( LDAP_DEBUG_FILTER, "=> comp_list_candidates 0x%x\n", ftype, 0, 0 );
232 for ( f = flist; f != NULL; f = f->cf_next ) {
233 /* ignore precomputed scopes */
234 if ( f->cf_choice == SLAPD_FILTER_COMPUTED &&
235 f->cf_result == LDAP_SUCCESS ) {
238 BDB_IDL_ZERO( save );
239 rc = comp_candidates( op, mra, f, save, tmp, save+BDB_IDL_UM_SIZE );
242 if ( ftype == LDAP_COMP_FILTER_AND ) {
249 if ( ftype == LDAP_COMP_FILTER_AND ) {
251 BDB_IDL_CPY( ids, save );
253 bdb_idl_intersection( ids, save );
255 if( BDB_IDL_IS_ZERO( ids ) )
259 BDB_IDL_CPY( ids, save );
261 bdb_idl_union( ids, save );
266 if( rc == LDAP_SUCCESS ) {
267 Debug( LDAP_DEBUG_FILTER,
268 "<= comp_list_candidates: id=%ld first=%ld last=%ld\n",
270 (long) BDB_IDL_FIRST(ids),
271 (long) BDB_IDL_LAST(ids) );
274 Debug( LDAP_DEBUG_FILTER,
275 "<= comp_list_candidates: undefined rc=%d\n",
283 comp_equality_candidates (
285 MatchingRuleAssertion *mra,
286 ComponentAssertion *ca,
291 struct bdb_info *bdb = (struct bdb_info *) op->o_bd->be_private;
296 struct berval prefix = {0, NULL};
297 struct berval *keys = NULL;
298 MatchingRule *mr = mra->ma_rule;
300 ComponentReference* cr_list, *cr;
302 BDB_IDL_ALL( bdb, ids );
304 bdb_attr_comp_ref ( op->o_bd->be_private, mra->ma_desc, &cr_list );
305 if( !cr_list || !ca->ca_comp_ref )
307 /* find a component reference to be indexed */
308 sat_syntax = ca->ca_ma_rule->smr_syntax;
309 for ( cr = cr_list ; cr ; cr = cr->cr_next ) {
310 if ( cr->cr_string.bv_len == ca->ca_comp_ref->cr_string.bv_len &&
311 strncmp( cr->cr_string.bv_val, ca->ca_comp_ref->cr_string.bv_val,cr->cr_string.bv_len ) == 0 )
318 rc = bdb_index_param( op->o_bd, mra->ma_desc, LDAP_FILTER_EQUALITY,
319 &db, &mask, &prefix );
321 if( rc != LDAP_SUCCESS ) {
332 if( !mr->smr_filter ) {
336 rc = (ca->ca_ma_rule->smr_filter)(
337 LDAP_FILTER_EQUALITY,
343 &keys, op->o_tmpmemctx );
345 if( rc != LDAP_SUCCESS ) {
352 for ( i= 0; keys[i].bv_val != NULL; i++ ) {
353 rc = bdb_key_read( op->o_bd, db, NULL, &keys[i], tmp, NULL, 0 );
355 if( rc == DB_NOTFOUND ) {
359 } else if( rc != LDAP_SUCCESS ) {
363 if( BDB_IDL_IS_ZERO( tmp ) ) {
369 BDB_IDL_CPY( ids, tmp );
371 bdb_idl_intersection( ids, tmp );
374 if( BDB_IDL_IS_ZERO( ids ) )
377 ber_bvarray_free_x( keys, op->o_tmpmemctx );
379 Debug( LDAP_DEBUG_TRACE,
380 "<= comp_equality_candidates: id=%ld, first=%ld, last=%ld\n",
382 (long) BDB_IDL_FIRST(ids),
383 (long) BDB_IDL_LAST(ids) );
388 ava_comp_candidates (
390 AttributeAssertion *ava,
391 AttributeAliasing *aa,
396 MatchingRuleAssertion mra;
398 mra.ma_rule = ava->aa_desc->ad_type->sat_equality;
399 if ( !mra.ma_rule ) {
400 struct bdb_info *bdb = (struct bdb_info *) op->o_bd->be_private;
401 BDB_IDL_ALL( bdb, ids );
404 mra.ma_desc = aa->aa_aliased_ad;
405 mra.ma_rule = ava->aa_desc->ad_type->sat_equality;
407 return comp_candidates ( op, &mra, ava->aa_cf, ids, tmp, stack );
413 MatchingRuleAssertion *mra,
421 if ( !f ) return LDAP_PROTOCOL_ERROR;
423 Debug( LDAP_DEBUG_FILTER, "comp_candidates\n", 0, 0, 0 );
424 switch ( f->cf_choice ) {
425 case SLAPD_FILTER_COMPUTED:
428 case LDAP_COMP_FILTER_AND:
429 rc = comp_list_candidates( op, mra, f->cf_and, LDAP_COMP_FILTER_AND, ids, tmp, stack );
431 case LDAP_COMP_FILTER_OR:
432 rc = comp_list_candidates( op, mra, f->cf_or, LDAP_COMP_FILTER_OR, ids, tmp, stack );
434 case LDAP_COMP_FILTER_NOT:
435 /* No component indexing supported for NOT filter */
436 Debug( LDAP_DEBUG_FILTER, "\tComponent NOT\n", 0, 0, 0 );
438 struct bdb_info *bdb = (struct bdb_info *) op->o_bd->be_private;
439 BDB_IDL_ALL( bdb, ids );
441 rc = LDAP_PROTOCOL_ERROR;
443 case LDAP_COMP_FILTER_ITEM:
444 rc = comp_equality_candidates( op, mra, f->cf_ca, ids, tmp, stack );
448 struct bdb_info *bdb = (struct bdb_info *) op->o_bd->be_private;
449 BDB_IDL_ALL( bdb, ids );
451 rc = LDAP_PROTOCOL_ERROR;
460 MatchingRuleAssertion *mra,
466 * Currently Only Component Indexing for componentFilterMatch is supported
467 * Indexing for an extensible filter is not supported yet
470 struct bdb_info *bdb = (struct bdb_info *) op->o_bd->be_private;
471 BDB_IDL_ALL( bdb, ids );
475 return comp_candidates ( op, mra, mra->ma_cf, ids, tmp, stack);
488 struct bdb_info *bdb = (struct bdb_info *) op->o_bd->be_private;
492 Debug( LDAP_DEBUG_FILTER, "=> bdb_list_candidates 0x%x\n", ftype, 0, 0 );
493 for ( f = flist; f != NULL; f = f->f_next ) {
494 /* ignore precomputed scopes */
495 if ( f->f_choice == SLAPD_FILTER_COMPUTED &&
496 f->f_result == LDAP_SUCCESS ) {
499 BDB_IDL_ZERO( save );
500 rc = bdb_filter_candidates( op, f, save, tmp,
501 save+BDB_IDL_UM_SIZE );
504 if ( ftype == LDAP_FILTER_AND ) {
512 if ( ftype == LDAP_FILTER_AND ) {
514 BDB_IDL_CPY( ids, save );
516 bdb_idl_intersection( ids, save );
518 if( BDB_IDL_IS_ZERO( ids ) )
522 BDB_IDL_CPY( ids, save );
524 bdb_idl_union( ids, save );
529 if( rc == LDAP_SUCCESS ) {
530 Debug( LDAP_DEBUG_FILTER,
531 "<= bdb_list_candidates: id=%ld first=%ld last=%ld\n",
533 (long) BDB_IDL_FIRST(ids),
534 (long) BDB_IDL_LAST(ids) );
537 Debug( LDAP_DEBUG_FILTER,
538 "<= bdb_list_candidates: undefined rc=%d\n",
548 AttributeDescription *desc,
551 struct bdb_info *bdb = (struct bdb_info *) op->o_bd->be_private;
555 struct berval prefix = {0, NULL};
557 Debug( LDAP_DEBUG_TRACE, "=> bdb_presence_candidates (%s)\n",
558 desc->ad_cname.bv_val, 0, 0 );
560 BDB_IDL_ALL( bdb, ids );
562 if( desc == slap_schema.si_ad_objectClass ) {
566 rc = bdb_index_param( op->o_bd, desc, LDAP_FILTER_PRESENT,
567 &db, &mask, &prefix );
569 if( rc != LDAP_SUCCESS ) {
570 Debug( LDAP_DEBUG_TRACE,
571 "<= bdb_presence_candidates: (%s) index_param "
573 desc->ad_cname.bv_val, rc, 0 );
579 Debug( LDAP_DEBUG_TRACE,
580 "<= bdb_presence_candidates: (%s) not indexed\n",
581 desc->ad_cname.bv_val, 0, 0 );
585 if( prefix.bv_val == NULL ) {
586 Debug( LDAP_DEBUG_TRACE,
587 "<= bdb_presence_candidates: (%s) no prefix\n",
588 desc->ad_cname.bv_val, 0, 0 );
592 rc = bdb_key_read( op->o_bd, db, NULL, &prefix, ids, NULL, 0 );
594 if( rc == DB_NOTFOUND ) {
597 } else if( rc != LDAP_SUCCESS ) {
598 Debug( LDAP_DEBUG_TRACE,
599 "<= bdb_presense_candidates: (%s) "
600 "key read failed (%d)\n",
601 desc->ad_cname.bv_val, rc, 0 );
605 Debug(LDAP_DEBUG_TRACE,
606 "<= bdb_presence_candidates: id=%ld first=%ld last=%ld\n",
608 (long) BDB_IDL_FIRST(ids),
609 (long) BDB_IDL_LAST(ids) );
618 AttributeAssertion *ava,
622 struct bdb_info *bdb = (struct bdb_info *) op->o_bd->be_private;
627 struct berval prefix = {0, NULL};
628 struct berval *keys = NULL;
631 Debug( LDAP_DEBUG_TRACE, "=> bdb_equality_candidates (%s)\n",
632 ava->aa_desc->ad_cname.bv_val, 0, 0 );
634 BDB_IDL_ALL( bdb, ids );
636 rc = bdb_index_param( op->o_bd, ava->aa_desc, LDAP_FILTER_EQUALITY,
637 &db, &mask, &prefix );
639 if( rc != LDAP_SUCCESS ) {
640 Debug( LDAP_DEBUG_ANY,
641 "<= bdb_equality_candidates: (%s) "
642 "index_param failed (%d)\n",
643 ava->aa_desc->ad_cname.bv_val, rc, 0 );
648 Debug( LDAP_DEBUG_ANY,
649 "<= bdb_equality_candidates: (%s) not indexed\n",
650 ava->aa_desc->ad_cname.bv_val, 0, 0 );
654 mr = ava->aa_desc->ad_type->sat_equality;
659 if( !mr->smr_filter ) {
663 rc = (mr->smr_filter)(
664 LDAP_FILTER_EQUALITY,
666 ava->aa_desc->ad_type->sat_syntax,
670 &keys, op->o_tmpmemctx );
672 if( rc != LDAP_SUCCESS ) {
673 Debug( LDAP_DEBUG_TRACE,
674 "<= bdb_equality_candidates: (%s, %s) "
675 "MR filter failed (%d)\n",
676 prefix.bv_val, ava->aa_desc->ad_cname.bv_val, rc );
681 Debug( LDAP_DEBUG_TRACE,
682 "<= bdb_equality_candidates: (%s) no keys\n",
683 ava->aa_desc->ad_cname.bv_val, 0, 0 );
687 for ( i= 0; keys[i].bv_val != NULL; i++ ) {
688 rc = bdb_key_read( op->o_bd, db, NULL, &keys[i], tmp, NULL, 0 );
690 if( rc == DB_NOTFOUND ) {
694 } else if( rc != LDAP_SUCCESS ) {
695 Debug( LDAP_DEBUG_TRACE,
696 "<= bdb_equality_candidates: (%s) "
697 "key read failed (%d)\n",
698 ava->aa_desc->ad_cname.bv_val, rc, 0 );
702 if( BDB_IDL_IS_ZERO( tmp ) ) {
703 Debug( LDAP_DEBUG_TRACE,
704 "<= bdb_equality_candidates: (%s) NULL\n",
705 ava->aa_desc->ad_cname.bv_val, 0, 0 );
711 BDB_IDL_CPY( ids, tmp );
713 bdb_idl_intersection( ids, tmp );
716 if( BDB_IDL_IS_ZERO( ids ) )
720 ber_bvarray_free_x( keys, op->o_tmpmemctx );
722 Debug( LDAP_DEBUG_TRACE,
723 "<= bdb_equality_candidates: id=%ld, first=%ld, last=%ld\n",
725 (long) BDB_IDL_FIRST(ids),
726 (long) BDB_IDL_LAST(ids) );
734 AttributeAssertion *ava,
738 struct bdb_info *bdb = (struct bdb_info *) op->o_bd->be_private;
743 struct berval prefix = {0, NULL};
744 struct berval *keys = NULL;
747 Debug( LDAP_DEBUG_TRACE, "=> bdb_approx_candidates (%s)\n",
748 ava->aa_desc->ad_cname.bv_val, 0, 0 );
750 BDB_IDL_ALL( bdb, ids );
752 rc = bdb_index_param( op->o_bd, ava->aa_desc, LDAP_FILTER_APPROX,
753 &db, &mask, &prefix );
755 if( rc != LDAP_SUCCESS ) {
756 Debug( LDAP_DEBUG_ANY,
757 "<= bdb_approx_candidates: (%s) "
758 "index_param failed (%d)\n",
759 ava->aa_desc->ad_cname.bv_val, rc, 0 );
764 Debug( LDAP_DEBUG_ANY,
765 "<= bdb_approx_candidates: (%s) not indexed\n",
766 ava->aa_desc->ad_cname.bv_val, 0, 0 );
770 mr = ava->aa_desc->ad_type->sat_approx;
772 /* no approx matching rule, try equality matching rule */
773 mr = ava->aa_desc->ad_type->sat_equality;
780 if( !mr->smr_filter ) {
784 rc = (mr->smr_filter)(
787 ava->aa_desc->ad_type->sat_syntax,
791 &keys, op->o_tmpmemctx );
793 if( rc != LDAP_SUCCESS ) {
794 Debug( LDAP_DEBUG_TRACE,
795 "<= bdb_approx_candidates: (%s, %s) "
796 "MR filter failed (%d)\n",
797 prefix.bv_val, ava->aa_desc->ad_cname.bv_val, rc );
802 Debug( LDAP_DEBUG_TRACE,
803 "<= bdb_approx_candidates: (%s) no keys (%s)\n",
804 prefix.bv_val, ava->aa_desc->ad_cname.bv_val, 0 );
808 for ( i= 0; keys[i].bv_val != NULL; i++ ) {
809 rc = bdb_key_read( op->o_bd, db, NULL, &keys[i], tmp, NULL, 0 );
811 if( rc == DB_NOTFOUND ) {
815 } else if( rc != LDAP_SUCCESS ) {
816 Debug( LDAP_DEBUG_TRACE,
817 "<= bdb_approx_candidates: (%s) "
818 "key read failed (%d)\n",
819 ava->aa_desc->ad_cname.bv_val, rc, 0 );
823 if( BDB_IDL_IS_ZERO( tmp ) ) {
824 Debug( LDAP_DEBUG_TRACE,
825 "<= bdb_approx_candidates: (%s) NULL\n",
826 ava->aa_desc->ad_cname.bv_val, 0, 0 );
832 BDB_IDL_CPY( ids, tmp );
834 bdb_idl_intersection( ids, tmp );
837 if( BDB_IDL_IS_ZERO( ids ) )
841 ber_bvarray_free_x( keys, op->o_tmpmemctx );
843 Debug( LDAP_DEBUG_TRACE, "<= bdb_approx_candidates %ld, first=%ld, last=%ld\n",
845 (long) BDB_IDL_FIRST(ids),
846 (long) BDB_IDL_LAST(ids) );
851 substring_candidates(
853 SubstringsAssertion *sub,
857 struct bdb_info *bdb = (struct bdb_info *) op->o_bd->be_private;
862 struct berval prefix = {0, NULL};
863 struct berval *keys = NULL;
866 Debug( LDAP_DEBUG_TRACE, "=> bdb_substring_candidates (%s)\n",
867 sub->sa_desc->ad_cname.bv_val, 0, 0 );
869 BDB_IDL_ALL( bdb, ids );
871 rc = bdb_index_param( op->o_bd, sub->sa_desc, LDAP_FILTER_SUBSTRINGS,
872 &db, &mask, &prefix );
874 if( rc != LDAP_SUCCESS ) {
875 Debug( LDAP_DEBUG_ANY,
876 "<= bdb_substring_candidates: (%s) "
877 "index_param failed (%d)\n",
878 sub->sa_desc->ad_cname.bv_val, rc, 0 );
883 Debug( LDAP_DEBUG_ANY,
884 "<= bdb_substring_candidates: (%s) not indexed\n",
885 sub->sa_desc->ad_cname.bv_val, 0, 0 );
889 mr = sub->sa_desc->ad_type->sat_substr;
895 if( !mr->smr_filter ) {
899 rc = (mr->smr_filter)(
900 LDAP_FILTER_SUBSTRINGS,
902 sub->sa_desc->ad_type->sat_syntax,
906 &keys, op->o_tmpmemctx );
908 if( rc != LDAP_SUCCESS ) {
909 Debug( LDAP_DEBUG_TRACE,
910 "<= bdb_substring_candidates: (%s) "
911 "MR filter failed (%d)\n",
912 sub->sa_desc->ad_cname.bv_val, rc, 0 );
917 Debug( LDAP_DEBUG_TRACE,
918 "<= bdb_substring_candidates: (0x%04lx) no keys (%s)\n",
919 mask, sub->sa_desc->ad_cname.bv_val, 0 );
923 for ( i= 0; keys[i].bv_val != NULL; i++ ) {
924 rc = bdb_key_read( op->o_bd, db, NULL, &keys[i], tmp, NULL, 0 );
926 if( rc == DB_NOTFOUND ) {
930 } else if( rc != LDAP_SUCCESS ) {
931 Debug( LDAP_DEBUG_TRACE,
932 "<= bdb_substring_candidates: (%s) "
933 "key read failed (%d)\n",
934 sub->sa_desc->ad_cname.bv_val, rc, 0 );
938 if( BDB_IDL_IS_ZERO( tmp ) ) {
939 Debug( LDAP_DEBUG_TRACE,
940 "<= bdb_substring_candidates: (%s) NULL\n",
941 sub->sa_desc->ad_cname.bv_val, 0, 0 );
947 BDB_IDL_CPY( ids, tmp );
949 bdb_idl_intersection( ids, tmp );
952 if( BDB_IDL_IS_ZERO( ids ) )
956 ber_bvarray_free_x( keys, op->o_tmpmemctx );
958 Debug( LDAP_DEBUG_TRACE, "<= bdb_substring_candidates: %ld, first=%ld, last=%ld\n",
960 (long) BDB_IDL_FIRST(ids),
961 (long) BDB_IDL_LAST(ids) );
966 inequality_candidates(
968 AttributeAssertion *ava,
973 struct bdb_info *bdb = (struct bdb_info *) op->o_bd->be_private;
978 struct berval prefix = {0, NULL};
979 struct berval *keys = NULL;
983 Debug( LDAP_DEBUG_TRACE, "=> bdb_inequality_candidates (%s)\n",
984 ava->aa_desc->ad_cname.bv_val, 0, 0 );
986 BDB_IDL_ALL( bdb, ids );
988 rc = bdb_index_param( op->o_bd, ava->aa_desc, LDAP_FILTER_EQUALITY,
989 &db, &mask, &prefix );
991 if( rc != LDAP_SUCCESS ) {
992 Debug( LDAP_DEBUG_ANY,
993 "<= bdb_inequality_candidates: (%s) "
994 "index_param failed (%d)\n",
995 ava->aa_desc->ad_cname.bv_val, rc, 0 );
1000 Debug( LDAP_DEBUG_ANY,
1001 "<= bdb_inequality_candidates: (%s) not indexed\n",
1002 ava->aa_desc->ad_cname.bv_val, 0, 0 );
1006 mr = ava->aa_desc->ad_type->sat_equality;
1011 if( !mr->smr_filter ) {
1015 rc = (mr->smr_filter)(
1016 LDAP_FILTER_EQUALITY,
1018 ava->aa_desc->ad_type->sat_syntax,
1022 &keys, op->o_tmpmemctx );
1024 if( rc != LDAP_SUCCESS ) {
1025 Debug( LDAP_DEBUG_TRACE,
1026 "<= bdb_inequality_candidates: (%s, %s) "
1027 "MR filter failed (%d)\n",
1028 prefix.bv_val, ava->aa_desc->ad_cname.bv_val, rc );
1032 if( keys == NULL ) {
1033 Debug( LDAP_DEBUG_TRACE,
1034 "<= bdb_inequality_candidates: (%s) no keys\n",
1035 ava->aa_desc->ad_cname.bv_val, 0, 0 );
1039 BDB_IDL_ZERO( ids );
1041 rc = bdb_key_read( op->o_bd, db, NULL, &keys[0], tmp, &cursor, gtorlt );
1043 if( rc == DB_NOTFOUND ) {
1046 } else if( rc != LDAP_SUCCESS ) {
1047 Debug( LDAP_DEBUG_TRACE,
1048 "<= bdb_inequality_candidates: (%s) "
1049 "key read failed (%d)\n",
1050 ava->aa_desc->ad_cname.bv_val, rc, 0 );
1054 if( BDB_IDL_IS_ZERO( tmp ) ) {
1055 Debug( LDAP_DEBUG_TRACE,
1056 "<= bdb_inequality_candidates: (%s) NULL\n",
1057 ava->aa_desc->ad_cname.bv_val, 0, 0 );
1061 bdb_idl_union( ids, tmp );
1063 if( BDB_IDL_IS_ZERO( ids ) )
1067 ber_bvarray_free_x( keys, op->o_tmpmemctx );
1069 Debug( LDAP_DEBUG_TRACE,
1070 "<= bdb_inequality_candidates: id=%ld, first=%ld, last=%ld\n",
1072 (long) BDB_IDL_FIRST(ids),
1073 (long) BDB_IDL_LAST(ids) );