From 8d8a52f9d26ca0f3cb23955761ef158a0212efd5 Mon Sep 17 00:00:00 2001 From: Howard Chu Date: Fri, 18 Apr 2003 03:36:52 +0000 Subject: [PATCH] ITS#2453, Fix filter candidate generation --- servers/slapd/back-bdb/filterindex.c | 44 ++++++++++++++++++++-------- servers/slapd/back-bdb/search.c | 8 ++--- 2 files changed, 36 insertions(+), 16 deletions(-) diff --git a/servers/slapd/back-bdb/filterindex.c b/servers/slapd/back-bdb/filterindex.c index 369b3f46b1..3b0ed135a3 100644 --- a/servers/slapd/back-bdb/filterindex.c +++ b/servers/slapd/back-bdb/filterindex.c @@ -58,6 +58,10 @@ bdb_filter_candidates( #endif switch ( f->f_choice ) { + case SLAPD_FILTER_COMPUTED: + rc = 0; + break; + case SLAPD_FILTER_DN_ONE: #ifdef NEW_LOGGING LDAP_LOG ( INDEX, ARGS, "=> bdb_filter_candidates: \tDN ONE\n", 0, 0, 0 ); @@ -212,12 +216,8 @@ list_candidates( Debug( LDAP_DEBUG_FILTER, "=> bdb_list_candidates 0x%x\n", ftype, 0, 0 ); #endif - if ( ftype == LDAP_FILTER_OR ) { - BDB_IDL_ALL( bdb, save ); - BDB_IDL_ZERO( ids ); - } else { - BDB_IDL_CPY( save, ids ); - } + /* Copy so we can propagate pre-computed IDLs */ + BDB_IDL_CPY( save, ids ); for ( f = flist; f != NULL; f = f->f_next ) { rc = bdb_filter_candidates( op, f, save, tmp, @@ -230,14 +230,22 @@ list_candidates( } break; } + if ( ftype == LDAP_FILTER_AND ) { - bdb_idl_intersection( ids, save ); + if ( f == flist ) { + BDB_IDL_CPY( ids, save ); + } else { + bdb_idl_intersection( ids, save ); + } if( BDB_IDL_IS_ZERO( ids ) ) break; } else { - bdb_idl_union( ids, save ); - BDB_IDL_ALL( bdb, save ); + if ( f == flist ) { + BDB_IDL_CPY( ids, save ); + } else { + bdb_idl_union( ids, save ); + } } } @@ -509,7 +517,11 @@ equality_candidates( break; } - bdb_idl_intersection( ids, tmp ); + if ( i == 0 ) { + BDB_IDL_CPY( ids, tmp ); + } else { + bdb_idl_intersection( ids, tmp ); + } if( BDB_IDL_IS_ZERO( ids ) ) break; @@ -674,7 +686,11 @@ approx_candidates( break; } - bdb_idl_intersection( ids, tmp ); + if ( i == 0 ) { + BDB_IDL_CPY( ids, tmp ); + } else { + bdb_idl_intersection( ids, tmp ); + } if( BDB_IDL_IS_ZERO( ids ) ) break; @@ -833,7 +849,11 @@ substring_candidates( break; } - bdb_idl_intersection( ids, tmp ); + if ( i == 0 ) { + BDB_IDL_CPY( ids, tmp ); + } else { + bdb_idl_intersection( ids, tmp ); + } if( BDB_IDL_IS_ZERO( ids ) ) break; diff --git a/servers/slapd/back-bdb/search.c b/servers/slapd/back-bdb/search.c index 046efa5471..91d8c7e501 100644 --- a/servers/slapd/back-bdb/search.c +++ b/servers/slapd/back-bdb/search.c @@ -164,7 +164,7 @@ static int search_aliases( af.f_next = NULL; /* Find all aliases in database */ - BDB_IDL_ALL( bdb, aliases ); + BDB_IDL_ZERO( aliases ); rs->sr_err = bdb_filter_candidates( op, &af, aliases, curscop, visited ); if (rs->sr_err != LDAP_SUCCESS) { @@ -670,7 +670,7 @@ dn2entry_retry: rs->sr_err = base_candidate( op->o_bd, &base, candidates ); } else { - BDB_IDL_ALL( bdb, candidates ); + BDB_IDL_ZERO( candidates ); BDB_IDL_ZERO( scopes ); rs->sr_err = search_candidates( op, sop, rs, &base, locker, candidates, scopes ); } @@ -1521,7 +1521,7 @@ static int search_candidates( f.f_choice = LDAP_FILTER_AND; f.f_and = &nf; /* Dummy; we compute scope separately now */ - nf.f_choice = LDAP_FILTER_NOT; + nf.f_choice = SLAPD_FILTER_COMPUTED; nf.f_next = xf.f_or == op->oq_search.rs_filter ? op->oq_search.rs_filter : &xf ; /* Filter depth increased again, adding dummy clause */ @@ -1534,7 +1534,7 @@ static int search_candidates( sf.f_ava = &aa_subentry; sf.f_av_desc = slap_schema.si_ad_objectClass; sf.f_av_value = bv_subentry; - sf.f_next = scopef.f_next; + sf.f_next = nf.f_next; nf.f_next = &sf; } #endif -- 2.39.5