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-2008 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 ) {
336 if( !mr->smr_filter ) {
340 rc = (ca->ca_ma_rule->smr_filter)(
341 LDAP_FILTER_EQUALITY,
347 &keys, op->o_tmpmemctx );
349 if( rc != LDAP_SUCCESS ) {
356 for ( i= 0; keys[i].bv_val != NULL; i++ ) {
357 rc = bdb_key_read( op->o_bd, db, NULL, &keys[i], tmp, NULL, 0 );
359 if( rc == DB_NOTFOUND ) {
363 } else if( rc != LDAP_SUCCESS ) {
367 if( BDB_IDL_IS_ZERO( tmp ) ) {
373 BDB_IDL_CPY( ids, tmp );
375 bdb_idl_intersection( ids, tmp );
378 if( BDB_IDL_IS_ZERO( ids ) )
381 ber_bvarray_free_x( keys, op->o_tmpmemctx );
383 Debug( LDAP_DEBUG_TRACE,
384 "<= comp_equality_candidates: id=%ld, first=%ld, last=%ld\n",
386 (long) BDB_IDL_FIRST(ids),
387 (long) BDB_IDL_LAST(ids) );
392 ava_comp_candidates (
394 AttributeAssertion *ava,
395 AttributeAliasing *aa,
400 MatchingRuleAssertion mra;
402 mra.ma_rule = ava->aa_desc->ad_type->sat_equality;
403 if ( !mra.ma_rule ) {
404 struct bdb_info *bdb = (struct bdb_info *) op->o_bd->be_private;
405 BDB_IDL_ALL( bdb, ids );
408 mra.ma_desc = aa->aa_aliased_ad;
409 mra.ma_rule = ava->aa_desc->ad_type->sat_equality;
411 return comp_candidates ( op, &mra, ava->aa_cf, ids, tmp, stack );
417 MatchingRuleAssertion *mra,
425 if ( !f ) return LDAP_PROTOCOL_ERROR;
427 Debug( LDAP_DEBUG_FILTER, "comp_candidates\n", 0, 0, 0 );
428 switch ( f->cf_choice ) {
429 case SLAPD_FILTER_COMPUTED:
432 case LDAP_COMP_FILTER_AND:
433 rc = comp_list_candidates( op, mra, f->cf_and, LDAP_COMP_FILTER_AND, ids, tmp, stack );
435 case LDAP_COMP_FILTER_OR:
436 rc = comp_list_candidates( op, mra, f->cf_or, LDAP_COMP_FILTER_OR, ids, tmp, stack );
438 case LDAP_COMP_FILTER_NOT:
439 /* No component indexing supported for NOT filter */
440 Debug( LDAP_DEBUG_FILTER, "\tComponent NOT\n", 0, 0, 0 );
442 struct bdb_info *bdb = (struct bdb_info *) op->o_bd->be_private;
443 BDB_IDL_ALL( bdb, ids );
445 rc = LDAP_PROTOCOL_ERROR;
447 case LDAP_COMP_FILTER_ITEM:
448 rc = comp_equality_candidates( op, mra, f->cf_ca, ids, tmp, stack );
452 struct bdb_info *bdb = (struct bdb_info *) op->o_bd->be_private;
453 BDB_IDL_ALL( bdb, ids );
455 rc = LDAP_PROTOCOL_ERROR;
464 MatchingRuleAssertion *mra,
470 * Currently Only Component Indexing for componentFilterMatch is supported
471 * Indexing for an extensible filter is not supported yet
474 struct bdb_info *bdb = (struct bdb_info *) op->o_bd->be_private;
475 BDB_IDL_ALL( bdb, ids );
479 return comp_candidates ( op, mra, mra->ma_cf, ids, tmp, stack);
495 Debug( LDAP_DEBUG_FILTER, "=> bdb_list_candidates 0x%x\n", ftype, 0, 0 );
496 for ( f = flist; f != NULL; f = f->f_next ) {
497 /* ignore precomputed scopes */
498 if ( f->f_choice == SLAPD_FILTER_COMPUTED &&
499 f->f_result == LDAP_SUCCESS ) {
502 BDB_IDL_ZERO( save );
503 rc = bdb_filter_candidates( op, f, save, tmp,
504 save+BDB_IDL_UM_SIZE );
507 if ( ftype == LDAP_FILTER_AND ) {
515 if ( ftype == LDAP_FILTER_AND ) {
517 BDB_IDL_CPY( ids, save );
519 bdb_idl_intersection( ids, save );
521 if( BDB_IDL_IS_ZERO( ids ) )
525 BDB_IDL_CPY( ids, save );
527 bdb_idl_union( ids, save );
532 if( rc == LDAP_SUCCESS ) {
533 Debug( LDAP_DEBUG_FILTER,
534 "<= bdb_list_candidates: id=%ld first=%ld last=%ld\n",
536 (long) BDB_IDL_FIRST(ids),
537 (long) BDB_IDL_LAST(ids) );
540 Debug( LDAP_DEBUG_FILTER,
541 "<= bdb_list_candidates: undefined rc=%d\n",
551 AttributeDescription *desc,
554 struct bdb_info *bdb = (struct bdb_info *) op->o_bd->be_private;
558 struct berval prefix = {0, NULL};
560 Debug( LDAP_DEBUG_TRACE, "=> bdb_presence_candidates (%s)\n",
561 desc->ad_cname.bv_val, 0, 0 );
563 BDB_IDL_ALL( bdb, ids );
565 if( desc == slap_schema.si_ad_objectClass ) {
569 rc = bdb_index_param( op->o_bd, desc, LDAP_FILTER_PRESENT,
570 &db, &mask, &prefix );
572 if( rc == LDAP_INAPPROPRIATE_MATCHING ) {
574 Debug( LDAP_DEBUG_TRACE,
575 "<= bdb_presence_candidates: (%s) not indexed\n",
576 desc->ad_cname.bv_val, 0, 0 );
580 if( rc != LDAP_SUCCESS ) {
581 Debug( LDAP_DEBUG_TRACE,
582 "<= bdb_presence_candidates: (%s) index_param "
584 desc->ad_cname.bv_val, rc, 0 );
588 if( prefix.bv_val == NULL ) {
589 Debug( LDAP_DEBUG_TRACE,
590 "<= bdb_presence_candidates: (%s) no prefix\n",
591 desc->ad_cname.bv_val, 0, 0 );
595 rc = bdb_key_read( op->o_bd, db, NULL, &prefix, ids, NULL, 0 );
597 if( rc == DB_NOTFOUND ) {
600 } else if( rc != LDAP_SUCCESS ) {
601 Debug( LDAP_DEBUG_TRACE,
602 "<= bdb_presense_candidates: (%s) "
603 "key read failed (%d)\n",
604 desc->ad_cname.bv_val, rc, 0 );
608 Debug(LDAP_DEBUG_TRACE,
609 "<= bdb_presence_candidates: id=%ld first=%ld last=%ld\n",
611 (long) BDB_IDL_FIRST(ids),
612 (long) BDB_IDL_LAST(ids) );
621 AttributeAssertion *ava,
625 struct bdb_info *bdb = (struct bdb_info *) op->o_bd->be_private;
630 struct berval prefix = {0, NULL};
631 struct berval *keys = NULL;
634 Debug( LDAP_DEBUG_TRACE, "=> bdb_equality_candidates (%s)\n",
635 ava->aa_desc->ad_cname.bv_val, 0, 0 );
637 BDB_IDL_ALL( bdb, ids );
639 rc = bdb_index_param( op->o_bd, ava->aa_desc, LDAP_FILTER_EQUALITY,
640 &db, &mask, &prefix );
642 if ( rc == LDAP_INAPPROPRIATE_MATCHING ) {
643 Debug( LDAP_DEBUG_ANY,
644 "<= bdb_equality_candidates: (%s) not indexed\n",
645 ava->aa_desc->ad_cname.bv_val, 0, 0 );
649 if( rc != LDAP_SUCCESS ) {
650 Debug( LDAP_DEBUG_ANY,
651 "<= bdb_equality_candidates: (%s) "
652 "index_param failed (%d)\n",
653 ava->aa_desc->ad_cname.bv_val, rc, 0 );
657 mr = ava->aa_desc->ad_type->sat_equality;
662 if( !mr->smr_filter ) {
666 rc = (mr->smr_filter)(
667 LDAP_FILTER_EQUALITY,
669 ava->aa_desc->ad_type->sat_syntax,
673 &keys, op->o_tmpmemctx );
675 if( rc != LDAP_SUCCESS ) {
676 Debug( LDAP_DEBUG_TRACE,
677 "<= bdb_equality_candidates: (%s, %s) "
678 "MR filter failed (%d)\n",
679 prefix.bv_val, ava->aa_desc->ad_cname.bv_val, rc );
684 Debug( LDAP_DEBUG_TRACE,
685 "<= bdb_equality_candidates: (%s) no keys\n",
686 ava->aa_desc->ad_cname.bv_val, 0, 0 );
690 for ( i= 0; keys[i].bv_val != NULL; i++ ) {
691 rc = bdb_key_read( op->o_bd, db, NULL, &keys[i], tmp, NULL, 0 );
693 if( rc == DB_NOTFOUND ) {
697 } else if( rc != LDAP_SUCCESS ) {
698 Debug( LDAP_DEBUG_TRACE,
699 "<= bdb_equality_candidates: (%s) "
700 "key read failed (%d)\n",
701 ava->aa_desc->ad_cname.bv_val, rc, 0 );
705 if( BDB_IDL_IS_ZERO( tmp ) ) {
706 Debug( LDAP_DEBUG_TRACE,
707 "<= bdb_equality_candidates: (%s) NULL\n",
708 ava->aa_desc->ad_cname.bv_val, 0, 0 );
714 BDB_IDL_CPY( ids, tmp );
716 bdb_idl_intersection( ids, tmp );
719 if( BDB_IDL_IS_ZERO( ids ) )
723 ber_bvarray_free_x( keys, op->o_tmpmemctx );
725 Debug( LDAP_DEBUG_TRACE,
726 "<= bdb_equality_candidates: id=%ld, first=%ld, last=%ld\n",
728 (long) BDB_IDL_FIRST(ids),
729 (long) BDB_IDL_LAST(ids) );
737 AttributeAssertion *ava,
741 struct bdb_info *bdb = (struct bdb_info *) op->o_bd->be_private;
746 struct berval prefix = {0, NULL};
747 struct berval *keys = NULL;
750 Debug( LDAP_DEBUG_TRACE, "=> bdb_approx_candidates (%s)\n",
751 ava->aa_desc->ad_cname.bv_val, 0, 0 );
753 BDB_IDL_ALL( bdb, ids );
755 rc = bdb_index_param( op->o_bd, ava->aa_desc, LDAP_FILTER_APPROX,
756 &db, &mask, &prefix );
758 if ( rc == LDAP_INAPPROPRIATE_MATCHING ) {
759 Debug( LDAP_DEBUG_ANY,
760 "<= bdb_approx_candidates: (%s) not indexed\n",
761 ava->aa_desc->ad_cname.bv_val, 0, 0 );
765 if( rc != LDAP_SUCCESS ) {
766 Debug( LDAP_DEBUG_ANY,
767 "<= bdb_approx_candidates: (%s) "
768 "index_param failed (%d)\n",
769 ava->aa_desc->ad_cname.bv_val, rc, 0 );
773 mr = ava->aa_desc->ad_type->sat_approx;
775 /* no approx matching rule, try equality matching rule */
776 mr = ava->aa_desc->ad_type->sat_equality;
783 if( !mr->smr_filter ) {
787 rc = (mr->smr_filter)(
790 ava->aa_desc->ad_type->sat_syntax,
794 &keys, op->o_tmpmemctx );
796 if( rc != LDAP_SUCCESS ) {
797 Debug( LDAP_DEBUG_TRACE,
798 "<= bdb_approx_candidates: (%s, %s) "
799 "MR filter failed (%d)\n",
800 prefix.bv_val, ava->aa_desc->ad_cname.bv_val, rc );
805 Debug( LDAP_DEBUG_TRACE,
806 "<= bdb_approx_candidates: (%s) no keys (%s)\n",
807 prefix.bv_val, ava->aa_desc->ad_cname.bv_val, 0 );
811 for ( i= 0; keys[i].bv_val != NULL; i++ ) {
812 rc = bdb_key_read( op->o_bd, db, NULL, &keys[i], tmp, NULL, 0 );
814 if( rc == DB_NOTFOUND ) {
818 } else if( rc != LDAP_SUCCESS ) {
819 Debug( LDAP_DEBUG_TRACE,
820 "<= bdb_approx_candidates: (%s) "
821 "key read failed (%d)\n",
822 ava->aa_desc->ad_cname.bv_val, rc, 0 );
826 if( BDB_IDL_IS_ZERO( tmp ) ) {
827 Debug( LDAP_DEBUG_TRACE,
828 "<= bdb_approx_candidates: (%s) NULL\n",
829 ava->aa_desc->ad_cname.bv_val, 0, 0 );
835 BDB_IDL_CPY( ids, tmp );
837 bdb_idl_intersection( ids, tmp );
840 if( BDB_IDL_IS_ZERO( ids ) )
844 ber_bvarray_free_x( keys, op->o_tmpmemctx );
846 Debug( LDAP_DEBUG_TRACE, "<= bdb_approx_candidates %ld, first=%ld, last=%ld\n",
848 (long) BDB_IDL_FIRST(ids),
849 (long) BDB_IDL_LAST(ids) );
854 substring_candidates(
856 SubstringsAssertion *sub,
860 struct bdb_info *bdb = (struct bdb_info *) op->o_bd->be_private;
865 struct berval prefix = {0, NULL};
866 struct berval *keys = NULL;
869 Debug( LDAP_DEBUG_TRACE, "=> bdb_substring_candidates (%s)\n",
870 sub->sa_desc->ad_cname.bv_val, 0, 0 );
872 BDB_IDL_ALL( bdb, ids );
874 rc = bdb_index_param( op->o_bd, sub->sa_desc, LDAP_FILTER_SUBSTRINGS,
875 &db, &mask, &prefix );
877 if ( rc == LDAP_INAPPROPRIATE_MATCHING ) {
878 Debug( LDAP_DEBUG_ANY,
879 "<= bdb_substring_candidates: (%s) not indexed\n",
880 sub->sa_desc->ad_cname.bv_val, 0, 0 );
884 if( rc != LDAP_SUCCESS ) {
885 Debug( LDAP_DEBUG_ANY,
886 "<= bdb_substring_candidates: (%s) "
887 "index_param failed (%d)\n",
888 sub->sa_desc->ad_cname.bv_val, rc, 0 );
892 mr = sub->sa_desc->ad_type->sat_substr;
898 if( !mr->smr_filter ) {
902 rc = (mr->smr_filter)(
903 LDAP_FILTER_SUBSTRINGS,
905 sub->sa_desc->ad_type->sat_syntax,
909 &keys, op->o_tmpmemctx );
911 if( rc != LDAP_SUCCESS ) {
912 Debug( LDAP_DEBUG_TRACE,
913 "<= bdb_substring_candidates: (%s) "
914 "MR filter failed (%d)\n",
915 sub->sa_desc->ad_cname.bv_val, rc, 0 );
920 Debug( LDAP_DEBUG_TRACE,
921 "<= bdb_substring_candidates: (0x%04lx) no keys (%s)\n",
922 mask, sub->sa_desc->ad_cname.bv_val, 0 );
926 for ( i= 0; keys[i].bv_val != NULL; i++ ) {
927 rc = bdb_key_read( op->o_bd, db, NULL, &keys[i], tmp, NULL, 0 );
929 if( rc == DB_NOTFOUND ) {
933 } else if( rc != LDAP_SUCCESS ) {
934 Debug( LDAP_DEBUG_TRACE,
935 "<= bdb_substring_candidates: (%s) "
936 "key read failed (%d)\n",
937 sub->sa_desc->ad_cname.bv_val, rc, 0 );
941 if( BDB_IDL_IS_ZERO( tmp ) ) {
942 Debug( LDAP_DEBUG_TRACE,
943 "<= bdb_substring_candidates: (%s) NULL\n",
944 sub->sa_desc->ad_cname.bv_val, 0, 0 );
950 BDB_IDL_CPY( ids, tmp );
952 bdb_idl_intersection( ids, tmp );
955 if( BDB_IDL_IS_ZERO( ids ) )
959 ber_bvarray_free_x( keys, op->o_tmpmemctx );
961 Debug( LDAP_DEBUG_TRACE, "<= bdb_substring_candidates: %ld, first=%ld, last=%ld\n",
963 (long) BDB_IDL_FIRST(ids),
964 (long) BDB_IDL_LAST(ids) );
969 inequality_candidates(
971 AttributeAssertion *ava,
976 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_INAPPROPRIATE_MATCHING ) {
994 Debug( LDAP_DEBUG_ANY,
995 "<= bdb_inequality_candidates: (%s) not indexed\n",
996 ava->aa_desc->ad_cname.bv_val, 0, 0 );
1000 if( rc != LDAP_SUCCESS ) {
1001 Debug( LDAP_DEBUG_ANY,
1002 "<= bdb_inequality_candidates: (%s) "
1003 "index_param failed (%d)\n",
1004 ava->aa_desc->ad_cname.bv_val, rc, 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( op->ors_limit && op->ors_limit->lms_s_unchecked != -1 &&
1066 BDB_IDL_N( ids ) >= (unsigned) op->ors_limit->lms_s_unchecked ) {
1067 cursor->c_close( cursor );
1071 ber_bvarray_free_x( keys, op->o_tmpmemctx );
1073 Debug( LDAP_DEBUG_TRACE,
1074 "<= bdb_inequality_candidates: id=%ld, first=%ld, last=%ld\n",
1076 (long) BDB_IDL_FIRST(ids),
1077 (long) BDB_IDL_LAST(ids) );