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-2018 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(
73 MatchingRuleAssertion *mra,
78 #ifdef LDAP_COMP_MATCH
83 MatchingRuleAssertion *mra,
93 AttributeAssertion *ava,
94 AttributeAliasing *aa,
101 mdb_filter_candidates(
110 #ifdef LDAP_COMP_MATCH
111 AttributeAliasing *aa;
113 Debug( LDAP_DEBUG_FILTER, "=> mdb_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:
135 /* this is a pre-computed scope, leave it alone */
139 case LDAP_FILTER_PRESENT:
140 Debug( LDAP_DEBUG_FILTER, "\tPRESENT\n", 0, 0, 0 );
141 rc = presence_candidates( op, rtxn, f->f_desc, ids );
144 case LDAP_FILTER_EQUALITY:
145 Debug( LDAP_DEBUG_FILTER, "\tEQUALITY\n", 0, 0, 0 );
146 #ifdef LDAP_COMP_MATCH
147 if ( is_aliased_attribute && ( aa = is_aliased_attribute ( f->f_ava->aa_desc ) ) ) {
148 rc = ava_comp_candidates ( op, rtxn, f->f_ava, aa, ids, tmp, stack );
153 rc = equality_candidates( op, rtxn, f->f_ava, ids, tmp );
157 case LDAP_FILTER_APPROX:
158 Debug( LDAP_DEBUG_FILTER, "\tAPPROX\n", 0, 0, 0 );
159 rc = approx_candidates( op, rtxn, f->f_ava, ids, tmp );
162 case LDAP_FILTER_SUBSTRINGS:
163 Debug( LDAP_DEBUG_FILTER, "\tSUBSTRINGS\n", 0, 0, 0 );
164 rc = substring_candidates( op, rtxn, f->f_sub, ids, tmp );
168 /* if no GE index, use pres */
169 Debug( LDAP_DEBUG_FILTER, "\tGE\n", 0, 0, 0 );
170 if( f->f_ava->aa_desc->ad_type->sat_ordering &&
171 ( f->f_ava->aa_desc->ad_type->sat_ordering->smr_usage & SLAP_MR_ORDERED_INDEX ) )
172 rc = inequality_candidates( op, rtxn, f->f_ava, ids, tmp, LDAP_FILTER_GE );
174 rc = presence_candidates( op, rtxn, f->f_ava->aa_desc, ids );
178 /* if no LE index, use pres */
179 Debug( LDAP_DEBUG_FILTER, "\tLE\n", 0, 0, 0 );
180 if( f->f_ava->aa_desc->ad_type->sat_ordering &&
181 ( f->f_ava->aa_desc->ad_type->sat_ordering->smr_usage & SLAP_MR_ORDERED_INDEX ) )
182 rc = inequality_candidates( op, rtxn, f->f_ava, ids, tmp, LDAP_FILTER_LE );
184 rc = presence_candidates( op, rtxn, f->f_ava->aa_desc, ids );
187 case LDAP_FILTER_NOT:
188 /* no indexing to support NOT filters */
189 Debug( LDAP_DEBUG_FILTER, "\tNOT\n", 0, 0, 0 );
193 case LDAP_FILTER_AND:
194 Debug( LDAP_DEBUG_FILTER, "\tAND\n", 0, 0, 0 );
195 rc = list_candidates( op, rtxn,
196 f->f_and, LDAP_FILTER_AND, ids, tmp, stack );
200 Debug( LDAP_DEBUG_FILTER, "\tOR\n", 0, 0, 0 );
201 rc = list_candidates( op, rtxn,
202 f->f_or, LDAP_FILTER_OR, ids, tmp, stack );
204 case LDAP_FILTER_EXT:
205 Debug( LDAP_DEBUG_FILTER, "\tEXT\n", 0, 0, 0 );
206 rc = ext_candidates( op, rtxn, f->f_mra, ids, tmp, stack );
209 Debug( LDAP_DEBUG_FILTER, "\tUNKNOWN %lu\n",
210 (unsigned long) f->f_choice, 0, 0 );
211 /* Must not return NULL, otherwise extended filters break */
214 if ( ids[2] == NOID && MDB_IDL_IS_RANGE( ids )) {
215 struct mdb_info *mdb = (struct mdb_info *) op->o_bd->be_private;
218 if ( mdb->mi_nextid ) {
219 last = mdb->mi_nextid;
225 rc = mdb_cursor_open( rtxn, mdb->mi_id2entry, &mc );
227 rc = mdb_cursor_get( mc, &key, NULL, MDB_LAST );
229 memcpy( &last, key.mv_data, sizeof( last ));
230 mdb_cursor_close( mc );
241 Debug( LDAP_DEBUG_FILTER,
242 "<= mdb_filter_candidates: id=%ld first=%ld last=%ld\n",
244 (long) MDB_IDL_FIRST( ids ),
245 (long) MDB_IDL_LAST( ids ) );
250 #ifdef LDAP_COMP_MATCH
252 comp_list_candidates(
255 MatchingRuleAssertion* mra,
256 ComponentFilter *flist,
265 Debug( LDAP_DEBUG_FILTER, "=> comp_list_candidates 0x%x\n", ftype, 0, 0 );
266 for ( f = flist; f != NULL; f = f->cf_next ) {
267 /* ignore precomputed scopes */
268 if ( f->cf_choice == SLAPD_FILTER_COMPUTED &&
269 f->cf_result == LDAP_SUCCESS ) {
272 MDB_IDL_ZERO( save );
273 rc = comp_candidates( op, rtxn, mra, f, save, tmp, save+MDB_IDL_UM_SIZE );
276 if ( ftype == LDAP_COMP_FILTER_AND ) {
283 if ( ftype == LDAP_COMP_FILTER_AND ) {
285 MDB_IDL_CPY( ids, save );
287 mdb_idl_intersection( ids, save );
289 if( MDB_IDL_IS_ZERO( ids ) )
293 MDB_IDL_CPY( ids, save );
295 mdb_idl_union( ids, save );
300 if( rc == LDAP_SUCCESS ) {
301 Debug( LDAP_DEBUG_FILTER,
302 "<= comp_list_candidates: id=%ld first=%ld last=%ld\n",
304 (long) MDB_IDL_FIRST(ids),
305 (long) MDB_IDL_LAST(ids) );
308 Debug( LDAP_DEBUG_FILTER,
309 "<= comp_list_candidates: undefined rc=%d\n",
317 comp_equality_candidates (
320 MatchingRuleAssertion *mra,
321 ComponentAssertion *ca,
330 struct berval prefix = {0, NULL};
331 struct berval *keys = NULL;
332 MatchingRule *mr = mra->ma_rule;
334 ComponentReference* cr_list, *cr;
339 if ( !ca->ca_comp_ref )
342 ai = mdb_attr_mask( op->o_bd->be_private, mra->ma_desc );
349 /* find a component reference to be indexed */
350 sat_syntax = ca->ca_ma_rule->smr_syntax;
351 for ( cr = cr_list ; cr ; cr = cr->cr_next ) {
352 if ( cr->cr_string.bv_len == ca->ca_comp_ref->cr_string.bv_len &&
353 strncmp( cr->cr_string.bv_val, ca->ca_comp_ref->cr_string.bv_val,cr->cr_string.bv_len ) == 0 )
360 rc = mdb_index_param( op->o_bd, mra->ma_desc, LDAP_FILTER_EQUALITY,
361 &dbi, &mask, &prefix );
363 if( rc != LDAP_SUCCESS ) {
371 if( !mr->smr_filter ) {
375 rc = (ca->ca_ma_rule->smr_filter)(
376 LDAP_FILTER_EQUALITY,
382 &keys, op->o_tmpmemctx );
384 if( rc != LDAP_SUCCESS ) {
391 for ( i= 0; keys[i].bv_val != NULL; i++ ) {
392 rc = mdb_key_read( op->o_bd, rtxn, dbi, &keys[i], tmp, NULL, 0 );
394 if( rc == MDB_NOTFOUND ) {
398 } else if( rc != LDAP_SUCCESS ) {
402 if( MDB_IDL_IS_ZERO( tmp ) ) {
408 MDB_IDL_CPY( ids, tmp );
410 mdb_idl_intersection( ids, tmp );
413 if( MDB_IDL_IS_ZERO( ids ) )
416 ber_bvarray_free_x( keys, op->o_tmpmemctx );
418 Debug( LDAP_DEBUG_TRACE,
419 "<= comp_equality_candidates: id=%ld, first=%ld, last=%ld\n",
421 (long) MDB_IDL_FIRST(ids),
422 (long) MDB_IDL_LAST(ids) );
427 ava_comp_candidates (
430 AttributeAssertion *ava,
431 AttributeAliasing *aa,
436 MatchingRuleAssertion mra;
438 mra.ma_rule = ava->aa_desc->ad_type->sat_equality;
439 if ( !mra.ma_rule ) {
443 mra.ma_desc = aa->aa_aliased_ad;
444 mra.ma_rule = ava->aa_desc->ad_type->sat_equality;
446 return comp_candidates ( op, rtxn, &mra, ava->aa_cf, ids, tmp, stack );
453 MatchingRuleAssertion *mra,
461 if ( !f ) return LDAP_PROTOCOL_ERROR;
463 Debug( LDAP_DEBUG_FILTER, "comp_candidates\n", 0, 0, 0 );
464 switch ( f->cf_choice ) {
465 case SLAPD_FILTER_COMPUTED:
468 case LDAP_COMP_FILTER_AND:
469 rc = comp_list_candidates( op, rtxn, mra, f->cf_and, LDAP_COMP_FILTER_AND, ids, tmp, stack );
471 case LDAP_COMP_FILTER_OR:
472 rc = comp_list_candidates( op, rtxn, mra, f->cf_or, LDAP_COMP_FILTER_OR, ids, tmp, stack );
474 case LDAP_COMP_FILTER_NOT:
475 /* No component indexing supported for NOT filter */
476 Debug( LDAP_DEBUG_FILTER, "\tComponent NOT\n", 0, 0, 0 );
478 rc = LDAP_PROTOCOL_ERROR;
480 case LDAP_COMP_FILTER_ITEM:
481 rc = comp_equality_candidates( op, rtxn, mra, f->cf_ca, ids, tmp, stack );
485 rc = LDAP_PROTOCOL_ERROR;
496 MatchingRuleAssertion *mra,
501 #ifdef LDAP_COMP_MATCH
503 * Currently Only Component Indexing for componentFilterMatch is supported
504 * Indexing for an extensible filter is not supported yet
507 return comp_candidates ( op, rtxn, mra, mra->ma_cf, ids, tmp, stack);
510 if ( mra->ma_desc == slap_schema.si_ad_entryDN ) {
515 if ( mra->ma_rule == slap_schema.si_mr_distinguishedNameMatch ) {
517 rc = mdb_dn2id( op, rtxn, NULL, &mra->ma_value, &id, NULL, NULL, NULL );
518 if ( rc == MDB_SUCCESS ) {
519 mdb_idl_insert( ids, id );
522 } else if ( mra->ma_rule && mra->ma_rule->smr_match ==
523 dnRelativeMatch && dnIsSuffix( &mra->ma_value,
524 op->o_bd->be_nsuffix )) {
526 if ( mra->ma_rule == slap_schema.si_mr_dnSuperiorMatch ) {
527 mdb_dn2sups( op, rtxn, &mra->ma_value, ids );
530 if ( mra->ma_rule == slap_schema.si_mr_dnSubtreeMatch )
531 scope = LDAP_SCOPE_SUBTREE;
532 else if ( mra->ma_rule == slap_schema.si_mr_dnOneLevelMatch )
533 scope = LDAP_SCOPE_ONELEVEL;
534 else if ( mra->ma_rule == slap_schema.si_mr_dnSubordinateMatch )
535 scope = LDAP_SCOPE_SUBORDINATE;
537 goto base; /* scope = LDAP_SCOPE_BASE; */
539 if ( scope > LDAP_SCOPE_BASE ) {
541 rc = mdb_cache_find_ndn( op, rtxn, &mra->ma_value, &ei );
543 mdb_cache_entryinfo_unlock( ei );
544 if ( rc == LDAP_SUCCESS ) {
545 int sc = op->ors_scope;
546 op->ors_scope = scope;
547 rc = mdb_dn2idl( op, rtxn, &mra->ma_value, ei, ids,
574 Debug( LDAP_DEBUG_FILTER, "=> mdb_list_candidates 0x%x\n", ftype, 0, 0 );
575 for ( f = flist; f != NULL; f = f->f_next ) {
576 /* ignore precomputed scopes */
577 if ( f->f_choice == SLAPD_FILTER_COMPUTED &&
578 f->f_result == LDAP_SUCCESS ) {
581 MDB_IDL_ZERO( save );
582 rc = mdb_filter_candidates( op, rtxn, f, save, tmp,
583 save+MDB_IDL_UM_SIZE );
586 if ( ftype == LDAP_FILTER_AND ) {
594 if ( ftype == LDAP_FILTER_AND ) {
596 MDB_IDL_CPY( ids, save );
598 mdb_idl_intersection( ids, save );
600 if( MDB_IDL_IS_ZERO( ids ) )
604 MDB_IDL_CPY( ids, save );
606 mdb_idl_union( ids, save );
611 if( rc == LDAP_SUCCESS ) {
612 Debug( LDAP_DEBUG_FILTER,
613 "<= mdb_list_candidates: id=%ld first=%ld last=%ld\n",
615 (long) MDB_IDL_FIRST(ids),
616 (long) MDB_IDL_LAST(ids) );
619 Debug( LDAP_DEBUG_FILTER,
620 "<= mdb_list_candidates: undefined rc=%d\n",
631 AttributeDescription *desc,
637 struct berval prefix = {0, NULL};
639 Debug( LDAP_DEBUG_TRACE, "=> mdb_presence_candidates (%s)\n",
640 desc->ad_cname.bv_val, 0, 0 );
644 if( desc == slap_schema.si_ad_objectClass ) {
648 rc = mdb_index_param( op->o_bd, desc, LDAP_FILTER_PRESENT,
649 &dbi, &mask, &prefix );
651 if( rc == LDAP_INAPPROPRIATE_MATCHING ) {
653 Debug( LDAP_DEBUG_TRACE,
654 "<= mdb_presence_candidates: (%s) not indexed\n",
655 desc->ad_cname.bv_val, 0, 0 );
659 if( rc != LDAP_SUCCESS ) {
660 Debug( LDAP_DEBUG_TRACE,
661 "<= mdb_presence_candidates: (%s) index_param "
663 desc->ad_cname.bv_val, rc, 0 );
667 if( prefix.bv_val == NULL ) {
668 Debug( LDAP_DEBUG_TRACE,
669 "<= mdb_presence_candidates: (%s) no prefix\n",
670 desc->ad_cname.bv_val, 0, 0 );
674 rc = mdb_key_read( op->o_bd, rtxn, dbi, &prefix, ids, NULL, 0 );
676 if( rc == MDB_NOTFOUND ) {
679 } else if( rc != LDAP_SUCCESS ) {
680 Debug( LDAP_DEBUG_TRACE,
681 "<= mdb_presense_candidates: (%s) "
682 "key read failed (%d)\n",
683 desc->ad_cname.bv_val, rc, 0 );
687 Debug(LDAP_DEBUG_TRACE,
688 "<= mdb_presence_candidates: id=%ld first=%ld last=%ld\n",
690 (long) MDB_IDL_FIRST(ids),
691 (long) MDB_IDL_LAST(ids) );
701 AttributeAssertion *ava,
709 struct berval prefix = {0, NULL};
710 struct berval *keys = NULL;
713 Debug( LDAP_DEBUG_TRACE, "=> mdb_equality_candidates (%s)\n",
714 ava->aa_desc->ad_cname.bv_val, 0, 0 );
716 if ( ava->aa_desc == slap_schema.si_ad_entryDN ) {
718 rc = mdb_dn2id( op, rtxn, NULL, &ava->aa_value, &id, NULL, NULL, NULL );
719 if ( rc == LDAP_SUCCESS ) {
720 /* exactly one ID can match */
724 if ( rc == MDB_NOTFOUND ) {
733 rc = mdb_index_param( op->o_bd, ava->aa_desc, LDAP_FILTER_EQUALITY,
734 &dbi, &mask, &prefix );
736 if ( rc == LDAP_INAPPROPRIATE_MATCHING ) {
737 Debug( LDAP_DEBUG_ANY,
738 "<= mdb_equality_candidates: (%s) not indexed\n",
739 ava->aa_desc->ad_cname.bv_val, 0, 0 );
743 if( rc != LDAP_SUCCESS ) {
744 Debug( LDAP_DEBUG_ANY,
745 "<= mdb_equality_candidates: (%s) "
746 "index_param failed (%d)\n",
747 ava->aa_desc->ad_cname.bv_val, rc, 0 );
751 mr = ava->aa_desc->ad_type->sat_equality;
756 if( !mr->smr_filter ) {
760 rc = (mr->smr_filter)(
761 LDAP_FILTER_EQUALITY,
763 ava->aa_desc->ad_type->sat_syntax,
767 &keys, op->o_tmpmemctx );
769 if( rc != LDAP_SUCCESS ) {
770 Debug( LDAP_DEBUG_TRACE,
771 "<= mdb_equality_candidates: (%s, %s) "
772 "MR filter failed (%d)\n",
773 prefix.bv_val, ava->aa_desc->ad_cname.bv_val, rc );
778 Debug( LDAP_DEBUG_TRACE,
779 "<= mdb_equality_candidates: (%s) no keys\n",
780 ava->aa_desc->ad_cname.bv_val, 0, 0 );
784 for ( i= 0; keys[i].bv_val != NULL; i++ ) {
785 rc = mdb_key_read( op->o_bd, rtxn, dbi, &keys[i], tmp, NULL, 0 );
787 if( rc == MDB_NOTFOUND ) {
791 } else if( rc != LDAP_SUCCESS ) {
792 Debug( LDAP_DEBUG_TRACE,
793 "<= mdb_equality_candidates: (%s) "
794 "key read failed (%d)\n",
795 ava->aa_desc->ad_cname.bv_val, rc, 0 );
799 if( MDB_IDL_IS_ZERO( tmp ) ) {
800 Debug( LDAP_DEBUG_TRACE,
801 "<= mdb_equality_candidates: (%s) NULL\n",
802 ava->aa_desc->ad_cname.bv_val, 0, 0 );
808 MDB_IDL_CPY( ids, tmp );
810 mdb_idl_intersection( ids, tmp );
813 if( MDB_IDL_IS_ZERO( ids ) )
817 ber_bvarray_free_x( keys, op->o_tmpmemctx );
819 Debug( LDAP_DEBUG_TRACE,
820 "<= mdb_equality_candidates: id=%ld, first=%ld, last=%ld\n",
822 (long) MDB_IDL_FIRST(ids),
823 (long) MDB_IDL_LAST(ids) );
832 AttributeAssertion *ava,
840 struct berval prefix = {0, NULL};
841 struct berval *keys = NULL;
844 Debug( LDAP_DEBUG_TRACE, "=> mdb_approx_candidates (%s)\n",
845 ava->aa_desc->ad_cname.bv_val, 0, 0 );
849 rc = mdb_index_param( op->o_bd, ava->aa_desc, LDAP_FILTER_APPROX,
850 &dbi, &mask, &prefix );
852 if ( rc == LDAP_INAPPROPRIATE_MATCHING ) {
853 Debug( LDAP_DEBUG_ANY,
854 "<= mdb_approx_candidates: (%s) not indexed\n",
855 ava->aa_desc->ad_cname.bv_val, 0, 0 );
859 if( rc != LDAP_SUCCESS ) {
860 Debug( LDAP_DEBUG_ANY,
861 "<= mdb_approx_candidates: (%s) "
862 "index_param failed (%d)\n",
863 ava->aa_desc->ad_cname.bv_val, rc, 0 );
867 mr = ava->aa_desc->ad_type->sat_approx;
869 /* no approx matching rule, try equality matching rule */
870 mr = ava->aa_desc->ad_type->sat_equality;
877 if( !mr->smr_filter ) {
881 rc = (mr->smr_filter)(
884 ava->aa_desc->ad_type->sat_syntax,
888 &keys, op->o_tmpmemctx );
890 if( rc != LDAP_SUCCESS ) {
891 Debug( LDAP_DEBUG_TRACE,
892 "<= mdb_approx_candidates: (%s, %s) "
893 "MR filter failed (%d)\n",
894 prefix.bv_val, ava->aa_desc->ad_cname.bv_val, rc );
899 Debug( LDAP_DEBUG_TRACE,
900 "<= mdb_approx_candidates: (%s) no keys (%s)\n",
901 prefix.bv_val, ava->aa_desc->ad_cname.bv_val, 0 );
905 for ( i= 0; keys[i].bv_val != NULL; i++ ) {
906 rc = mdb_key_read( op->o_bd, rtxn, dbi, &keys[i], tmp, NULL, 0 );
908 if( rc == MDB_NOTFOUND ) {
912 } else if( rc != LDAP_SUCCESS ) {
913 Debug( LDAP_DEBUG_TRACE,
914 "<= mdb_approx_candidates: (%s) "
915 "key read failed (%d)\n",
916 ava->aa_desc->ad_cname.bv_val, rc, 0 );
920 if( MDB_IDL_IS_ZERO( tmp ) ) {
921 Debug( LDAP_DEBUG_TRACE,
922 "<= mdb_approx_candidates: (%s) NULL\n",
923 ava->aa_desc->ad_cname.bv_val, 0, 0 );
929 MDB_IDL_CPY( ids, tmp );
931 mdb_idl_intersection( ids, tmp );
934 if( MDB_IDL_IS_ZERO( ids ) )
938 ber_bvarray_free_x( keys, op->o_tmpmemctx );
940 Debug( LDAP_DEBUG_TRACE, "<= mdb_approx_candidates %ld, first=%ld, last=%ld\n",
942 (long) MDB_IDL_FIRST(ids),
943 (long) MDB_IDL_LAST(ids) );
948 substring_candidates(
951 SubstringsAssertion *sub,
959 struct berval prefix = {0, NULL};
960 struct berval *keys = NULL;
963 Debug( LDAP_DEBUG_TRACE, "=> mdb_substring_candidates (%s)\n",
964 sub->sa_desc->ad_cname.bv_val, 0, 0 );
968 rc = mdb_index_param( op->o_bd, sub->sa_desc, LDAP_FILTER_SUBSTRINGS,
969 &dbi, &mask, &prefix );
971 if ( rc == LDAP_INAPPROPRIATE_MATCHING ) {
972 Debug( LDAP_DEBUG_ANY,
973 "<= mdb_substring_candidates: (%s) not indexed\n",
974 sub->sa_desc->ad_cname.bv_val, 0, 0 );
978 if( rc != LDAP_SUCCESS ) {
979 Debug( LDAP_DEBUG_ANY,
980 "<= mdb_substring_candidates: (%s) "
981 "index_param failed (%d)\n",
982 sub->sa_desc->ad_cname.bv_val, rc, 0 );
986 mr = sub->sa_desc->ad_type->sat_substr;
992 if( !mr->smr_filter ) {
996 rc = (mr->smr_filter)(
997 LDAP_FILTER_SUBSTRINGS,
999 sub->sa_desc->ad_type->sat_syntax,
1003 &keys, op->o_tmpmemctx );
1005 if( rc != LDAP_SUCCESS ) {
1006 Debug( LDAP_DEBUG_TRACE,
1007 "<= mdb_substring_candidates: (%s) "
1008 "MR filter failed (%d)\n",
1009 sub->sa_desc->ad_cname.bv_val, rc, 0 );
1013 if( keys == NULL ) {
1014 Debug( LDAP_DEBUG_TRACE,
1015 "<= mdb_substring_candidates: (0x%04lx) no keys (%s)\n",
1016 mask, sub->sa_desc->ad_cname.bv_val, 0 );
1020 for ( i= 0; keys[i].bv_val != NULL; i++ ) {
1021 rc = mdb_key_read( op->o_bd, rtxn, dbi, &keys[i], tmp, NULL, 0 );
1023 if( rc == MDB_NOTFOUND ) {
1024 MDB_IDL_ZERO( ids );
1027 } else if( rc != LDAP_SUCCESS ) {
1028 Debug( LDAP_DEBUG_TRACE,
1029 "<= mdb_substring_candidates: (%s) "
1030 "key read failed (%d)\n",
1031 sub->sa_desc->ad_cname.bv_val, rc, 0 );
1035 if( MDB_IDL_IS_ZERO( tmp ) ) {
1036 Debug( LDAP_DEBUG_TRACE,
1037 "<= mdb_substring_candidates: (%s) NULL\n",
1038 sub->sa_desc->ad_cname.bv_val, 0, 0 );
1039 MDB_IDL_ZERO( ids );
1044 MDB_IDL_CPY( ids, tmp );
1046 mdb_idl_intersection( ids, tmp );
1049 if( MDB_IDL_IS_ZERO( ids ) )
1053 ber_bvarray_free_x( keys, op->o_tmpmemctx );
1055 Debug( LDAP_DEBUG_TRACE, "<= mdb_substring_candidates: %ld, first=%ld, last=%ld\n",
1057 (long) MDB_IDL_FIRST(ids),
1058 (long) MDB_IDL_LAST(ids) );
1063 inequality_candidates(
1066 AttributeAssertion *ava,
1074 struct berval prefix = {0, NULL};
1075 struct berval *keys = NULL;
1077 MDB_cursor *cursor = NULL;
1079 Debug( LDAP_DEBUG_TRACE, "=> mdb_inequality_candidates (%s)\n",
1080 ava->aa_desc->ad_cname.bv_val, 0, 0 );
1084 rc = mdb_index_param( op->o_bd, ava->aa_desc, LDAP_FILTER_EQUALITY,
1085 &dbi, &mask, &prefix );
1087 if ( rc == LDAP_INAPPROPRIATE_MATCHING ) {
1088 Debug( LDAP_DEBUG_ANY,
1089 "<= mdb_inequality_candidates: (%s) not indexed\n",
1090 ava->aa_desc->ad_cname.bv_val, 0, 0 );
1094 if( rc != LDAP_SUCCESS ) {
1095 Debug( LDAP_DEBUG_ANY,
1096 "<= mdb_inequality_candidates: (%s) "
1097 "index_param failed (%d)\n",
1098 ava->aa_desc->ad_cname.bv_val, rc, 0 );
1102 mr = ava->aa_desc->ad_type->sat_equality;
1107 if( !mr->smr_filter ) {
1111 rc = (mr->smr_filter)(
1112 LDAP_FILTER_EQUALITY,
1114 ava->aa_desc->ad_type->sat_syntax,
1118 &keys, op->o_tmpmemctx );
1120 if( rc != LDAP_SUCCESS ) {
1121 Debug( LDAP_DEBUG_TRACE,
1122 "<= mdb_inequality_candidates: (%s, %s) "
1123 "MR filter failed (%d)\n",
1124 prefix.bv_val, ava->aa_desc->ad_cname.bv_val, rc );
1128 if( keys == NULL ) {
1129 Debug( LDAP_DEBUG_TRACE,
1130 "<= mdb_inequality_candidates: (%s) no keys\n",
1131 ava->aa_desc->ad_cname.bv_val, 0, 0 );
1135 MDB_IDL_ZERO( ids );
1137 rc = mdb_key_read( op->o_bd, rtxn, dbi, &keys[0], tmp, &cursor, gtorlt );
1139 if( rc == MDB_NOTFOUND ) {
1142 } else if( rc != LDAP_SUCCESS ) {
1143 Debug( LDAP_DEBUG_TRACE,
1144 "<= mdb_inequality_candidates: (%s) "
1145 "key read failed (%d)\n",
1146 ava->aa_desc->ad_cname.bv_val, rc, 0 );
1150 if( MDB_IDL_IS_ZERO( tmp ) ) {
1151 Debug( LDAP_DEBUG_TRACE,
1152 "<= mdb_inequality_candidates: (%s) NULL\n",
1153 ava->aa_desc->ad_cname.bv_val, 0, 0 );
1157 mdb_idl_union( ids, tmp );
1159 if( op->ors_limit && op->ors_limit->lms_s_unchecked != -1 &&
1160 MDB_IDL_N( ids ) >= (unsigned) op->ors_limit->lms_s_unchecked ) {
1161 mdb_cursor_close( cursor );
1165 ber_bvarray_free_x( keys, op->o_tmpmemctx );
1167 Debug( LDAP_DEBUG_TRACE,
1168 "<= mdb_inequality_candidates: id=%ld, first=%ld, last=%ld\n",
1170 (long) MDB_IDL_FIRST(ids),
1171 (long) MDB_IDL_LAST(ids) );