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(
31 AttributeDescription *desc,
34 static int equality_candidates(
37 AttributeAssertion *ava,
40 static int inequality_candidates(
43 AttributeAssertion *ava,
47 static int approx_candidates(
50 AttributeAssertion *ava,
53 static int substring_candidates(
56 SubstringsAssertion *sub,
60 static int list_candidates(
69 #ifdef LDAP_COMP_MATCH
74 MatchingRuleAssertion *mra,
83 MatchingRuleAssertion *mra,
93 AttributeAssertion *ava,
94 AttributeAliasing *aa,
101 bdb_filter_candidates(
110 #ifdef LDAP_COMP_MATCH
111 AttributeAliasing *aa;
113 Debug( LDAP_DEBUG_FILTER, "=> bdb_filter_candidates\n", 0, 0, 0 );
115 if ( f->f_choice & SLAPD_FILTER_UNDEFINED ) {
120 switch ( f->f_choice ) {
121 case SLAPD_FILTER_COMPUTED:
122 switch( f->f_result ) {
123 case SLAPD_COMPARE_UNDEFINED:
124 /* This technically is not the same as FALSE, but it
125 * certainly will produce no matches.
128 case LDAP_COMPARE_FALSE:
131 case LDAP_COMPARE_TRUE: {
132 struct bdb_info *bdb = (struct bdb_info *)op->o_bd->be_private;
133 BDB_IDL_ALL( bdb, ids );
136 /* this is a pre-computed scope, leave it alone */
140 case LDAP_FILTER_PRESENT:
141 Debug( LDAP_DEBUG_FILTER, "\tPRESENT\n", 0, 0, 0 );
142 rc = presence_candidates( op, locker, f->f_desc, ids );
145 case LDAP_FILTER_EQUALITY:
146 Debug( LDAP_DEBUG_FILTER, "\tEQUALITY\n", 0, 0, 0 );
147 #ifdef LDAP_COMP_MATCH
148 if ( is_aliased_attribute && ( aa = is_aliased_attribute ( f->f_ava->aa_desc ) ) ) {
149 rc = ava_comp_candidates ( op, locker, f->f_ava, aa, ids, tmp, stack );
154 rc = equality_candidates( op, locker, f->f_ava, ids, tmp );
158 case LDAP_FILTER_APPROX:
159 Debug( LDAP_DEBUG_FILTER, "\tAPPROX\n", 0, 0, 0 );
160 rc = approx_candidates( op, locker, f->f_ava, ids, tmp );
163 case LDAP_FILTER_SUBSTRINGS:
164 Debug( LDAP_DEBUG_FILTER, "\tSUBSTRINGS\n", 0, 0, 0 );
165 rc = substring_candidates( op, locker, f->f_sub, ids, tmp );
169 /* if no GE index, use pres */
170 Debug( LDAP_DEBUG_FILTER, "\tGE\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, locker, f->f_ava, ids, tmp, LDAP_FILTER_GE );
175 rc = presence_candidates( op, locker, f->f_ava->aa_desc, ids );
179 /* if no LE index, use pres */
180 Debug( LDAP_DEBUG_FILTER, "\tLE\n", 0, 0, 0 );
181 if( f->f_ava->aa_desc->ad_type->sat_ordering &&
182 ( f->f_ava->aa_desc->ad_type->sat_ordering->smr_usage & SLAP_MR_ORDERED_INDEX ) )
183 rc = inequality_candidates( op, locker, f->f_ava, ids, tmp, LDAP_FILTER_LE );
185 rc = presence_candidates( op, locker, f->f_ava->aa_desc, ids );
188 case LDAP_FILTER_NOT:
189 /* no indexing to support NOT filters */
190 Debug( LDAP_DEBUG_FILTER, "\tNOT\n", 0, 0, 0 );
191 { struct bdb_info *bdb = (struct bdb_info *) op->o_bd->be_private;
192 BDB_IDL_ALL( bdb, ids );
196 case LDAP_FILTER_AND:
197 Debug( LDAP_DEBUG_FILTER, "\tAND\n", 0, 0, 0 );
198 rc = list_candidates( op, locker,
199 f->f_and, LDAP_FILTER_AND, ids, tmp, stack );
203 Debug( LDAP_DEBUG_FILTER, "\tOR\n", 0, 0, 0 );
204 rc = list_candidates( op, locker,
205 f->f_or, LDAP_FILTER_OR, ids, tmp, stack );
207 #ifdef LDAP_COMP_MATCH
208 case LDAP_FILTER_EXT:
209 Debug( LDAP_DEBUG_FILTER, "\tEXT\n", 0, 0, 0 );
210 rc = ext_candidates( op, locker, f->f_mra, ids, tmp, stack );
214 Debug( LDAP_DEBUG_FILTER, "\tUNKNOWN %lu\n",
215 (unsigned long) f->f_choice, 0, 0 );
216 /* Must not return NULL, otherwise extended filters break */
217 { struct bdb_info *bdb = (struct bdb_info *) op->o_bd->be_private;
218 BDB_IDL_ALL( bdb, ids );
223 Debug( LDAP_DEBUG_FILTER,
224 "<= bdb_filter_candidates: id=%ld first=%ld last=%ld\n",
226 (long) BDB_IDL_FIRST( ids ),
227 (long) BDB_IDL_LAST( ids ) );
232 #ifdef LDAP_COMP_MATCH
234 comp_list_candidates(
237 MatchingRuleAssertion* mra,
238 ComponentFilter *flist,
247 Debug( LDAP_DEBUG_FILTER, "=> comp_list_candidates 0x%x\n", ftype, 0, 0 );
248 for ( f = flist; f != NULL; f = f->cf_next ) {
249 /* ignore precomputed scopes */
250 if ( f->cf_choice == SLAPD_FILTER_COMPUTED &&
251 f->cf_result == LDAP_SUCCESS ) {
254 BDB_IDL_ZERO( save );
255 rc = comp_candidates( op, locker, mra, f, save, tmp, save+BDB_IDL_UM_SIZE );
258 if ( ftype == LDAP_COMP_FILTER_AND ) {
265 if ( ftype == LDAP_COMP_FILTER_AND ) {
267 BDB_IDL_CPY( ids, save );
269 bdb_idl_intersection( ids, save );
271 if( BDB_IDL_IS_ZERO( ids ) )
275 BDB_IDL_CPY( ids, save );
277 bdb_idl_union( ids, save );
282 if( rc == LDAP_SUCCESS ) {
283 Debug( LDAP_DEBUG_FILTER,
284 "<= comp_list_candidates: id=%ld first=%ld last=%ld\n",
286 (long) BDB_IDL_FIRST(ids),
287 (long) BDB_IDL_LAST(ids) );
290 Debug( LDAP_DEBUG_FILTER,
291 "<= comp_list_candidates: undefined rc=%d\n",
299 comp_equality_candidates (
302 MatchingRuleAssertion *mra,
303 ComponentAssertion *ca,
308 struct bdb_info *bdb = (struct bdb_info *) op->o_bd->be_private;
313 struct berval prefix = {0, NULL};
314 struct berval *keys = NULL;
315 MatchingRule *mr = mra->ma_rule;
317 ComponentReference* cr_list, *cr;
320 BDB_IDL_ALL( bdb, ids );
322 if ( !ca->ca_comp_ref )
325 ai = bdb_attr_mask( op->o_bd->be_private, mra->ma_desc );
332 /* find a component reference to be indexed */
333 sat_syntax = ca->ca_ma_rule->smr_syntax;
334 for ( cr = cr_list ; cr ; cr = cr->cr_next ) {
335 if ( cr->cr_string.bv_len == ca->ca_comp_ref->cr_string.bv_len &&
336 strncmp( cr->cr_string.bv_val, ca->ca_comp_ref->cr_string.bv_val,cr->cr_string.bv_len ) == 0 )
343 rc = bdb_index_param( op->o_bd, mra->ma_desc, LDAP_FILTER_EQUALITY,
344 &db, &mask, &prefix );
346 if( rc != LDAP_SUCCESS ) {
357 if( !mr->smr_filter ) {
361 rc = (ca->ca_ma_rule->smr_filter)(
362 LDAP_FILTER_EQUALITY,
368 &keys, op->o_tmpmemctx );
370 if( rc != LDAP_SUCCESS ) {
377 for ( i= 0; keys[i].bv_val != NULL; i++ ) {
378 rc = bdb_key_read( op->o_bd, db, locker, &keys[i], tmp, NULL, 0 );
380 if( rc == DB_NOTFOUND ) {
384 } else if( rc != LDAP_SUCCESS ) {
388 if( BDB_IDL_IS_ZERO( tmp ) ) {
394 BDB_IDL_CPY( ids, tmp );
396 bdb_idl_intersection( ids, tmp );
399 if( BDB_IDL_IS_ZERO( ids ) )
402 ber_bvarray_free_x( keys, op->o_tmpmemctx );
404 Debug( LDAP_DEBUG_TRACE,
405 "<= comp_equality_candidates: id=%ld, first=%ld, last=%ld\n",
407 (long) BDB_IDL_FIRST(ids),
408 (long) BDB_IDL_LAST(ids) );
413 ava_comp_candidates (
416 AttributeAssertion *ava,
417 AttributeAliasing *aa,
422 MatchingRuleAssertion mra;
424 mra.ma_rule = ava->aa_desc->ad_type->sat_equality;
425 if ( !mra.ma_rule ) {
426 struct bdb_info *bdb = (struct bdb_info *) op->o_bd->be_private;
427 BDB_IDL_ALL( bdb, ids );
430 mra.ma_desc = aa->aa_aliased_ad;
431 mra.ma_rule = ava->aa_desc->ad_type->sat_equality;
433 return comp_candidates ( op, locker, &mra, ava->aa_cf, ids, tmp, stack );
440 MatchingRuleAssertion *mra,
448 if ( !f ) return LDAP_PROTOCOL_ERROR;
450 Debug( LDAP_DEBUG_FILTER, "comp_candidates\n", 0, 0, 0 );
451 switch ( f->cf_choice ) {
452 case SLAPD_FILTER_COMPUTED:
455 case LDAP_COMP_FILTER_AND:
456 rc = comp_list_candidates( op, locker, mra, f->cf_and, LDAP_COMP_FILTER_AND, ids, tmp, stack );
458 case LDAP_COMP_FILTER_OR:
459 rc = comp_list_candidates( op, locker, mra, f->cf_or, LDAP_COMP_FILTER_OR, ids, tmp, stack );
461 case LDAP_COMP_FILTER_NOT:
462 /* No component indexing supported for NOT filter */
463 Debug( LDAP_DEBUG_FILTER, "\tComponent NOT\n", 0, 0, 0 );
465 struct bdb_info *bdb = (struct bdb_info *) op->o_bd->be_private;
466 BDB_IDL_ALL( bdb, ids );
468 rc = LDAP_PROTOCOL_ERROR;
470 case LDAP_COMP_FILTER_ITEM:
471 rc = comp_equality_candidates( op, locker, mra, f->cf_ca, ids, tmp, stack );
475 struct bdb_info *bdb = (struct bdb_info *) op->o_bd->be_private;
476 BDB_IDL_ALL( bdb, ids );
478 rc = LDAP_PROTOCOL_ERROR;
488 MatchingRuleAssertion *mra,
494 * Currently Only Component Indexing for componentFilterMatch is supported
495 * Indexing for an extensible filter is not supported yet
498 struct bdb_info *bdb = (struct bdb_info *) op->o_bd->be_private;
499 BDB_IDL_ALL( bdb, ids );
503 return comp_candidates ( op, locker, mra, mra->ma_cf, ids, tmp, stack);
520 Debug( LDAP_DEBUG_FILTER, "=> bdb_list_candidates 0x%x\n", ftype, 0, 0 );
521 for ( f = flist; f != NULL; f = f->f_next ) {
522 /* ignore precomputed scopes */
523 if ( f->f_choice == SLAPD_FILTER_COMPUTED &&
524 f->f_result == LDAP_SUCCESS ) {
527 BDB_IDL_ZERO( save );
528 rc = bdb_filter_candidates( op, locker, f, save, tmp,
529 save+BDB_IDL_UM_SIZE );
532 if ( ftype == LDAP_FILTER_AND ) {
540 if ( ftype == LDAP_FILTER_AND ) {
542 BDB_IDL_CPY( ids, save );
544 bdb_idl_intersection( ids, save );
546 if( BDB_IDL_IS_ZERO( ids ) )
550 BDB_IDL_CPY( ids, save );
552 bdb_idl_union( ids, save );
557 if( rc == LDAP_SUCCESS ) {
558 Debug( LDAP_DEBUG_FILTER,
559 "<= bdb_list_candidates: id=%ld first=%ld last=%ld\n",
561 (long) BDB_IDL_FIRST(ids),
562 (long) BDB_IDL_LAST(ids) );
565 Debug( LDAP_DEBUG_FILTER,
566 "<= bdb_list_candidates: undefined rc=%d\n",
577 AttributeDescription *desc,
580 struct bdb_info *bdb = (struct bdb_info *) op->o_bd->be_private;
584 struct berval prefix = {0, NULL};
586 Debug( LDAP_DEBUG_TRACE, "=> bdb_presence_candidates (%s)\n",
587 desc->ad_cname.bv_val, 0, 0 );
589 BDB_IDL_ALL( bdb, ids );
591 if( desc == slap_schema.si_ad_objectClass ) {
595 rc = bdb_index_param( op->o_bd, desc, LDAP_FILTER_PRESENT,
596 &db, &mask, &prefix );
598 if( rc != LDAP_SUCCESS ) {
599 Debug( LDAP_DEBUG_TRACE,
600 "<= bdb_presence_candidates: (%s) index_param "
602 desc->ad_cname.bv_val, rc, 0 );
608 Debug( LDAP_DEBUG_TRACE,
609 "<= bdb_presence_candidates: (%s) not indexed\n",
610 desc->ad_cname.bv_val, 0, 0 );
614 if( prefix.bv_val == NULL ) {
615 Debug( LDAP_DEBUG_TRACE,
616 "<= bdb_presence_candidates: (%s) no prefix\n",
617 desc->ad_cname.bv_val, 0, 0 );
621 rc = bdb_key_read( op->o_bd, db, locker, &prefix, ids, NULL, 0 );
623 if( rc == DB_NOTFOUND ) {
626 } else if( rc != LDAP_SUCCESS ) {
627 Debug( LDAP_DEBUG_TRACE,
628 "<= bdb_presense_candidates: (%s) "
629 "key read failed (%d)\n",
630 desc->ad_cname.bv_val, rc, 0 );
634 Debug(LDAP_DEBUG_TRACE,
635 "<= bdb_presence_candidates: id=%ld first=%ld last=%ld\n",
637 (long) BDB_IDL_FIRST(ids),
638 (long) BDB_IDL_LAST(ids) );
648 AttributeAssertion *ava,
652 struct bdb_info *bdb = (struct bdb_info *) op->o_bd->be_private;
657 struct berval prefix = {0, NULL};
658 struct berval *keys = NULL;
661 Debug( LDAP_DEBUG_TRACE, "=> bdb_equality_candidates (%s)\n",
662 ava->aa_desc->ad_cname.bv_val, 0, 0 );
664 BDB_IDL_ALL( bdb, ids );
666 rc = bdb_index_param( op->o_bd, ava->aa_desc, LDAP_FILTER_EQUALITY,
667 &db, &mask, &prefix );
669 if( rc != LDAP_SUCCESS ) {
670 Debug( LDAP_DEBUG_ANY,
671 "<= bdb_equality_candidates: (%s) "
672 "index_param failed (%d)\n",
673 ava->aa_desc->ad_cname.bv_val, rc, 0 );
678 Debug( LDAP_DEBUG_ANY,
679 "<= bdb_equality_candidates: (%s) not indexed\n",
680 ava->aa_desc->ad_cname.bv_val, 0, 0 );
684 mr = ava->aa_desc->ad_type->sat_equality;
689 if( !mr->smr_filter ) {
693 rc = (mr->smr_filter)(
694 LDAP_FILTER_EQUALITY,
696 ava->aa_desc->ad_type->sat_syntax,
700 &keys, op->o_tmpmemctx );
702 if( rc != LDAP_SUCCESS ) {
703 Debug( LDAP_DEBUG_TRACE,
704 "<= bdb_equality_candidates: (%s, %s) "
705 "MR filter failed (%d)\n",
706 prefix.bv_val, ava->aa_desc->ad_cname.bv_val, rc );
711 Debug( LDAP_DEBUG_TRACE,
712 "<= bdb_equality_candidates: (%s) no keys\n",
713 ava->aa_desc->ad_cname.bv_val, 0, 0 );
717 for ( i= 0; keys[i].bv_val != NULL; i++ ) {
718 rc = bdb_key_read( op->o_bd, db, locker, &keys[i], tmp, NULL, 0 );
720 if( rc == DB_NOTFOUND ) {
724 } else if( rc != LDAP_SUCCESS ) {
725 Debug( LDAP_DEBUG_TRACE,
726 "<= bdb_equality_candidates: (%s) "
727 "key read failed (%d)\n",
728 ava->aa_desc->ad_cname.bv_val, rc, 0 );
732 if( BDB_IDL_IS_ZERO( tmp ) ) {
733 Debug( LDAP_DEBUG_TRACE,
734 "<= bdb_equality_candidates: (%s) NULL\n",
735 ava->aa_desc->ad_cname.bv_val, 0, 0 );
741 BDB_IDL_CPY( ids, tmp );
743 bdb_idl_intersection( ids, tmp );
746 if( BDB_IDL_IS_ZERO( ids ) )
750 ber_bvarray_free_x( keys, op->o_tmpmemctx );
752 Debug( LDAP_DEBUG_TRACE,
753 "<= bdb_equality_candidates: id=%ld, first=%ld, last=%ld\n",
755 (long) BDB_IDL_FIRST(ids),
756 (long) BDB_IDL_LAST(ids) );
765 AttributeAssertion *ava,
769 struct bdb_info *bdb = (struct bdb_info *) op->o_bd->be_private;
774 struct berval prefix = {0, NULL};
775 struct berval *keys = NULL;
778 Debug( LDAP_DEBUG_TRACE, "=> bdb_approx_candidates (%s)\n",
779 ava->aa_desc->ad_cname.bv_val, 0, 0 );
781 BDB_IDL_ALL( bdb, ids );
783 rc = bdb_index_param( op->o_bd, ava->aa_desc, LDAP_FILTER_APPROX,
784 &db, &mask, &prefix );
786 if( rc != LDAP_SUCCESS ) {
787 Debug( LDAP_DEBUG_ANY,
788 "<= bdb_approx_candidates: (%s) "
789 "index_param failed (%d)\n",
790 ava->aa_desc->ad_cname.bv_val, rc, 0 );
795 Debug( LDAP_DEBUG_ANY,
796 "<= bdb_approx_candidates: (%s) not indexed\n",
797 ava->aa_desc->ad_cname.bv_val, 0, 0 );
801 mr = ava->aa_desc->ad_type->sat_approx;
803 /* no approx matching rule, try equality matching rule */
804 mr = ava->aa_desc->ad_type->sat_equality;
811 if( !mr->smr_filter ) {
815 rc = (mr->smr_filter)(
818 ava->aa_desc->ad_type->sat_syntax,
822 &keys, op->o_tmpmemctx );
824 if( rc != LDAP_SUCCESS ) {
825 Debug( LDAP_DEBUG_TRACE,
826 "<= bdb_approx_candidates: (%s, %s) "
827 "MR filter failed (%d)\n",
828 prefix.bv_val, ava->aa_desc->ad_cname.bv_val, rc );
833 Debug( LDAP_DEBUG_TRACE,
834 "<= bdb_approx_candidates: (%s) no keys (%s)\n",
835 prefix.bv_val, ava->aa_desc->ad_cname.bv_val, 0 );
839 for ( i= 0; keys[i].bv_val != NULL; i++ ) {
840 rc = bdb_key_read( op->o_bd, db, locker, &keys[i], tmp, NULL, 0 );
842 if( rc == DB_NOTFOUND ) {
846 } else if( rc != LDAP_SUCCESS ) {
847 Debug( LDAP_DEBUG_TRACE,
848 "<= bdb_approx_candidates: (%s) "
849 "key read failed (%d)\n",
850 ava->aa_desc->ad_cname.bv_val, rc, 0 );
854 if( BDB_IDL_IS_ZERO( tmp ) ) {
855 Debug( LDAP_DEBUG_TRACE,
856 "<= bdb_approx_candidates: (%s) NULL\n",
857 ava->aa_desc->ad_cname.bv_val, 0, 0 );
863 BDB_IDL_CPY( ids, tmp );
865 bdb_idl_intersection( ids, tmp );
868 if( BDB_IDL_IS_ZERO( ids ) )
872 ber_bvarray_free_x( keys, op->o_tmpmemctx );
874 Debug( LDAP_DEBUG_TRACE, "<= bdb_approx_candidates %ld, first=%ld, last=%ld\n",
876 (long) BDB_IDL_FIRST(ids),
877 (long) BDB_IDL_LAST(ids) );
882 substring_candidates(
885 SubstringsAssertion *sub,
889 struct bdb_info *bdb = (struct bdb_info *) op->o_bd->be_private;
894 struct berval prefix = {0, NULL};
895 struct berval *keys = NULL;
898 Debug( LDAP_DEBUG_TRACE, "=> bdb_substring_candidates (%s)\n",
899 sub->sa_desc->ad_cname.bv_val, 0, 0 );
901 BDB_IDL_ALL( bdb, ids );
903 rc = bdb_index_param( op->o_bd, sub->sa_desc, LDAP_FILTER_SUBSTRINGS,
904 &db, &mask, &prefix );
906 if( rc != LDAP_SUCCESS ) {
907 Debug( LDAP_DEBUG_ANY,
908 "<= bdb_substring_candidates: (%s) "
909 "index_param failed (%d)\n",
910 sub->sa_desc->ad_cname.bv_val, rc, 0 );
915 Debug( LDAP_DEBUG_ANY,
916 "<= bdb_substring_candidates: (%s) not indexed\n",
917 sub->sa_desc->ad_cname.bv_val, 0, 0 );
921 mr = sub->sa_desc->ad_type->sat_substr;
927 if( !mr->smr_filter ) {
931 rc = (mr->smr_filter)(
932 LDAP_FILTER_SUBSTRINGS,
934 sub->sa_desc->ad_type->sat_syntax,
938 &keys, op->o_tmpmemctx );
940 if( rc != LDAP_SUCCESS ) {
941 Debug( LDAP_DEBUG_TRACE,
942 "<= bdb_substring_candidates: (%s) "
943 "MR filter failed (%d)\n",
944 sub->sa_desc->ad_cname.bv_val, rc, 0 );
949 Debug( LDAP_DEBUG_TRACE,
950 "<= bdb_substring_candidates: (0x%04lx) no keys (%s)\n",
951 mask, sub->sa_desc->ad_cname.bv_val, 0 );
955 for ( i= 0; keys[i].bv_val != NULL; i++ ) {
956 rc = bdb_key_read( op->o_bd, db, locker, &keys[i], tmp, NULL, 0 );
958 if( rc == DB_NOTFOUND ) {
962 } else if( rc != LDAP_SUCCESS ) {
963 Debug( LDAP_DEBUG_TRACE,
964 "<= bdb_substring_candidates: (%s) "
965 "key read failed (%d)\n",
966 sub->sa_desc->ad_cname.bv_val, rc, 0 );
970 if( BDB_IDL_IS_ZERO( tmp ) ) {
971 Debug( LDAP_DEBUG_TRACE,
972 "<= bdb_substring_candidates: (%s) NULL\n",
973 sub->sa_desc->ad_cname.bv_val, 0, 0 );
979 BDB_IDL_CPY( ids, tmp );
981 bdb_idl_intersection( ids, tmp );
984 if( BDB_IDL_IS_ZERO( ids ) )
988 ber_bvarray_free_x( keys, op->o_tmpmemctx );
990 Debug( LDAP_DEBUG_TRACE, "<= bdb_substring_candidates: %ld, first=%ld, last=%ld\n",
992 (long) BDB_IDL_FIRST(ids),
993 (long) BDB_IDL_LAST(ids) );
998 inequality_candidates(
1001 AttributeAssertion *ava,
1006 struct bdb_info *bdb = (struct bdb_info *) op->o_bd->be_private;
1010 struct berval prefix = {0, NULL};
1011 struct berval *keys = NULL;
1013 DBC * cursor = NULL;
1015 Debug( LDAP_DEBUG_TRACE, "=> bdb_inequality_candidates (%s)\n",
1016 ava->aa_desc->ad_cname.bv_val, 0, 0 );
1018 BDB_IDL_ALL( bdb, ids );
1020 rc = bdb_index_param( op->o_bd, ava->aa_desc, LDAP_FILTER_EQUALITY,
1021 &db, &mask, &prefix );
1023 if( rc != LDAP_SUCCESS ) {
1024 Debug( LDAP_DEBUG_ANY,
1025 "<= bdb_inequality_candidates: (%s) "
1026 "index_param failed (%d)\n",
1027 ava->aa_desc->ad_cname.bv_val, rc, 0 );
1032 Debug( LDAP_DEBUG_ANY,
1033 "<= bdb_inequality_candidates: (%s) not indexed\n",
1034 ava->aa_desc->ad_cname.bv_val, 0, 0 );
1038 mr = ava->aa_desc->ad_type->sat_equality;
1043 if( !mr->smr_filter ) {
1047 rc = (mr->smr_filter)(
1048 LDAP_FILTER_EQUALITY,
1050 ava->aa_desc->ad_type->sat_syntax,
1054 &keys, op->o_tmpmemctx );
1056 if( rc != LDAP_SUCCESS ) {
1057 Debug( LDAP_DEBUG_TRACE,
1058 "<= bdb_inequality_candidates: (%s, %s) "
1059 "MR filter failed (%d)\n",
1060 prefix.bv_val, ava->aa_desc->ad_cname.bv_val, rc );
1064 if( keys == NULL ) {
1065 Debug( LDAP_DEBUG_TRACE,
1066 "<= bdb_inequality_candidates: (%s) no keys\n",
1067 ava->aa_desc->ad_cname.bv_val, 0, 0 );
1071 BDB_IDL_ZERO( ids );
1073 rc = bdb_key_read( op->o_bd, db, locker, &keys[0], tmp, &cursor, gtorlt );
1075 if( rc == DB_NOTFOUND ) {
1078 } else if( rc != LDAP_SUCCESS ) {
1079 Debug( LDAP_DEBUG_TRACE,
1080 "<= bdb_inequality_candidates: (%s) "
1081 "key read failed (%d)\n",
1082 ava->aa_desc->ad_cname.bv_val, rc, 0 );
1086 if( BDB_IDL_IS_ZERO( tmp ) ) {
1087 Debug( LDAP_DEBUG_TRACE,
1088 "<= bdb_inequality_candidates: (%s) NULL\n",
1089 ava->aa_desc->ad_cname.bv_val, 0, 0 );
1093 bdb_idl_union( ids, tmp );
1095 if( op->ors_limit && op->ors_limit->lms_s_unchecked != -1 &&
1096 BDB_IDL_N( ids ) >= (unsigned) op->ors_limit->lms_s_unchecked ) {
1097 cursor->c_close( cursor );
1101 ber_bvarray_free_x( keys, op->o_tmpmemctx );
1103 Debug( LDAP_DEBUG_TRACE,
1104 "<= bdb_inequality_candidates: id=%ld, first=%ld, last=%ld\n",
1106 (long) BDB_IDL_FIRST(ids),
1107 (long) BDB_IDL_LAST(ids) );