]> git.sur5r.net Git - openldap/blobdiff - servers/slapd/back-bdb/index.c
enable unindexed searches monitoring ifdef LDAP_DEVEL
[openldap] / servers / slapd / back-bdb / index.c
index 0e17da25b7661b48d9402e02a238e4299d331010..e193dae30d90e5ab122931421e12b28f2dbe0ac5 100644 (file)
@@ -2,7 +2,7 @@
 /* $OpenLDAP$ */
 /* This work is part of OpenLDAP Software <http://www.openldap.org/>.
  *
- * Copyright 2000-2005 The OpenLDAP Foundation.
+ * Copyright 2000-2007 The OpenLDAP Foundation.
  * All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
@@ -48,7 +48,7 @@ static AttrInfo *index_mask(
                /* has tagging option */
                ai = bdb_attr_mask( be->be_private, desc->ad_type->sat_ad );
 
-               if ( ai && ( ai->ai_indexmask ^ SLAP_INDEX_NOTAGS ) ) {
+               if ( ai && !( ai->ai_indexmask & SLAP_INDEX_NOTAGS ) ) {
                        *atname = desc->ad_type->sat_cname;
                        return ai;
                }
@@ -61,7 +61,7 @@ static AttrInfo *index_mask(
 
                ai = bdb_attr_mask( be->be_private, at->sat_ad );
 
-               if ( ai && ( ai->ai_indexmask ^ SLAP_INDEX_NOSUBTYPES ) ) {
+               if ( ai && !( ai->ai_indexmask & SLAP_INDEX_NOSUBTYPES ) ) {
                        *atname = at->sat_cname;
                        return ai;
                }
@@ -97,12 +97,32 @@ int bdb_index_param(
 {
        AttrInfo *ai;
        int rc;
-       slap_mask_t mask;
+       slap_mask_t mask, type = 0;
        DB *db;
 
        ai = index_mask( be, desc, prefixp );
 
-       if( !ai ) {
+       if ( !ai ) {
+#ifdef BDB_MONITOR_IDX
+               switch ( ftype ) {
+               case LDAP_FILTER_PRESENT:
+                       type = SLAP_INDEX_PRESENT;
+                       break;
+               case LDAP_FILTER_APPROX:
+                       type = SLAP_INDEX_APPROX;
+                       break;
+               case LDAP_FILTER_EQUALITY:
+                       type = SLAP_INDEX_EQUALITY;
+                       break;
+               case LDAP_FILTER_SUBSTRINGS:
+                       type = SLAP_INDEX_SUBSTR;
+                       break;
+               default:
+                       return LDAP_INAPPROPRIATE_MATCHING;
+               }
+               bdb_monitor_idx_add( be->be_private, desc, type );
+#endif /* BDB_MONITOR_IDX */
+
                return LDAP_INAPPROPRIATE_MATCHING;
        }
        mask = ai->ai_indexmask;
@@ -115,6 +135,7 @@ int bdb_index_param(
 
        switch( ftype ) {
        case LDAP_FILTER_PRESENT:
+               type = SLAP_INDEX_PRESENT;
                if( IS_SLAP_INDEX( mask, SLAP_INDEX_PRESENT ) ) {
                        *prefixp = presence_key;
                        goto done;
@@ -122,6 +143,7 @@ int bdb_index_param(
                break;
 
        case LDAP_FILTER_APPROX:
+               type = SLAP_INDEX_APPROX;
                if ( desc->ad_type->sat_approx ) {
                        if( IS_SLAP_INDEX( mask, SLAP_INDEX_APPROX ) ) {
                                goto done;
@@ -133,12 +155,14 @@ int bdb_index_param(
                /* fall thru */
 
        case LDAP_FILTER_EQUALITY:
+               type = SLAP_INDEX_EQUALITY;
                if( IS_SLAP_INDEX( mask, SLAP_INDEX_EQUALITY ) ) {
                        goto done;
                }
                break;
 
        case LDAP_FILTER_SUBSTRINGS:
+               type = SLAP_INDEX_SUBSTR;
                if( IS_SLAP_INDEX( mask, SLAP_INDEX_SUBSTR ) ) {
                        goto done;
                }
@@ -148,6 +172,10 @@ int bdb_index_param(
                return LDAP_OTHER;
        }
 
+#ifdef BDB_MONITOR_IDX
+       bdb_monitor_idx_add( be->be_private, desc, type );
+#endif /* BDB_MONITOR_IDX */
+
        return LDAP_INAPPROPRIATE_MATCHING;
 
 done:
@@ -377,6 +405,84 @@ int bdb_index_values(
        return rc;
 }
 
+/* Get the list of which indices apply to this attr */
+int
+bdb_index_recset(
+       struct bdb_info *bdb,
+       Attribute *a,
+       AttributeType *type,
+       struct berval *tags,
+       IndexRec *ir )
+{
+       int rc, slot;
+       AttrList *al;
+
+       if( type->sat_sup ) {
+               /* recurse */
+               rc = bdb_index_recset( bdb, a, type->sat_sup, tags, ir );
+               if( rc ) return rc;
+       }
+       /* If this type has no AD, we've never used it before */
+       if( type->sat_ad ) {
+               slot = bdb_attr_slot( bdb, type->sat_ad, NULL );
+               if ( slot >= 0 ) {
+                       ir[slot].ai = bdb->bi_attrs[slot];
+                       al = ch_malloc( sizeof( AttrList ));
+                       al->attr = a;
+                       al->next = ir[slot].attrs;
+                       ir[slot].attrs = al;
+               }
+       }
+       if( tags->bv_len ) {
+               AttributeDescription *desc;
+
+               desc = ad_find_tags( type, tags );
+               if( desc ) {
+                       slot = bdb_attr_slot( bdb, desc, NULL );
+                       if ( slot >= 0 ) {
+                               ir[slot].ai = bdb->bi_attrs[slot];
+                               al = ch_malloc( sizeof( AttrList ));
+                               al->attr = a;
+                               al->next = ir[slot].attrs;
+                               ir[slot].attrs = al;
+                       }
+               }
+       }
+       return LDAP_SUCCESS;
+}
+
+/* Apply the indices for the recset */
+int bdb_index_recrun(
+       Operation *op,
+       struct bdb_info *bdb,
+       IndexRec *ir0,
+       ID id,
+       int base )
+{
+       IndexRec *ir;
+       AttrList *al;
+       int i, rc = 0;
+
+       /* Never index ID 0 */
+       if ( id == 0 )
+               return 0;
+
+       for (i=base; i<bdb->bi_nattrs; i+=slap_tool_thread_max) {
+               ir = ir0 + i;
+               if ( !ir->ai ) continue;
+               while (( al = ir->attrs )) {
+                       ir->attrs = al->next;
+                       rc = indexer( op, NULL, ir->ai->ai_desc,
+                               &ir->ai->ai_desc->ad_type->sat_cname,
+                               al->attr->a_nvals, id, SLAP_INDEX_ADD_OP,
+                               ir->ai->ai_indexmask );
+                       free( al );
+                       if ( rc ) break;
+               }
+       }
+       return rc;
+}
+
 int
 bdb_index_entry(
        Operation *op,
@@ -398,6 +504,10 @@ bdb_index_entry(
        struct berval value = {0};
 #endif
 
+       /* Never index ID 0 */
+       if ( e->e_id == 0 )
+               return 0;
+
        Debug( LDAP_DEBUG_TRACE, "=> index_entry_%s( %ld, \"%s\" )\n",
                opid == SLAP_INDEX_DELETE_OP ? "del" : "add",
                (long) e->e_id, e->e_dn );
@@ -408,8 +518,8 @@ bdb_index_entry(
                AttrInfo *ai;
                /* see if attribute has components to be indexed */
                ai = bdb_attr_mask( op->o_bd->be_private, ap->a_desc->ad_type->sat_ad );
-               if ( ai ) cr_list = ai->ai_cr;
-               else cr_list = NULL;
+               if ( !ai ) continue;
+               cr_list = ai->ai_cr;
                if ( attr_converter && cr_list ) {
                        syn = ap->a_desc->ad_type->sat_syntax;
                        ap->a_comp_data = op->o_tmpalloc( sizeof( ComponentData ), op->o_tmpmemctx );