]> git.sur5r.net Git - openldap/commitdiff
Modify performance patch from Gertjan van Wingerde <gwingerde@home.nl>
authorHoward Chu <hyc@openldap.org>
Sun, 13 Jan 2002 23:23:23 +0000 (23:23 +0000)
committerHoward Chu <hyc@openldap.org>
Sun, 13 Jan 2002 23:23:23 +0000 (23:23 +0000)
servers/slapd/attr.c
servers/slapd/back-bdb/index.c
servers/slapd/back-bdb/modify.c
servers/slapd/back-bdb/proto-bdb.h
servers/slapd/back-ldap/search.c
servers/slapd/back-ldbm/index.c
servers/slapd/back-ldbm/proto-back-ldbm.h
servers/slapd/back-meta/search.c
servers/slapd/entry.c
servers/slapd/operational.c
servers/slapd/slap.h

index 462fead661a3b445db26e729b84f3b6e49f268c6..a4ef93f7b37cd9f21aee801a742d3145b6da401e 100644 (file)
@@ -74,6 +74,7 @@ Attribute *attr_dup( Attribute *a )
 
        tmp->a_desc = a->a_desc;
        tmp->a_next = NULL;
+       tmp->a_flags = 0;
 
        return tmp;
 }
@@ -125,6 +126,7 @@ attr_merge(
                (*a)->a_desc = desc;
                (*a)->a_vals = NULL;
                (*a)->a_next = NULL;
+               (*a)->a_flags = 0;
        }
 
        return( value_add( &(*a)->a_vals, vals ) );
index b22c3f6598e26876558210767b24b12fb3af79ff..c62e09d63fa592718bec842bb8d9a315d6271226 100644 (file)
@@ -75,6 +75,24 @@ static slap_mask_t index_mask(
        return 0;
 }
 
+int bdb_index_is_indexed(
+       Backend *be,
+       AttributeDescription *desc )
+{
+       int rc;
+       slap_mask_t mask;
+       char *dbname;
+       struct berval prefix;
+
+       mask = index_mask( be, desc, &dbname, &prefix );
+
+       if( mask == 0 ) {
+               return LDAP_INAPPROPRIATE_MATCHING;
+       }
+
+       return LDAP_SUCCESS;
+}
+
 int bdb_index_param(
        Backend *be,
        AttributeDescription *desc,
index 435ae651b8ea4214e7ce131636fc9df657d5a5f9..6d9cc6c4be256d4f3e5ec9195e4ac4644864b4da 100644 (file)
@@ -33,6 +33,7 @@ int bdb_modify_internal(
        Modification    *mod;
        Modifications   *ml;
        Attribute       *save_attrs;
+       Attribute       *ap;
 
        Debug( LDAP_DEBUG_TRACE, "bdb_modify_internal: 0x%08lx: %s\n",
                e->e_id, e->e_dn, 0);
@@ -115,6 +116,16 @@ int bdb_modify_internal(
                        /* unlock entry, delete from cache */
                        return err; 
                }
+
+               /* check if modified attribute was indexed */
+               err = bdb_index_is_indexed( be, mod->sm_desc );
+               if ( err == LDAP_SUCCESS ) {
+                       ap = attr_find( save_attrs, mod->sm_desc );
+                       if ( ap ) ap->a_flags |= SLAP_ATTR_IXDEL;
+
+                       ap = attr_find( e->e_attrs, mod->sm_desc );
+                       if ( ap ) ap->a_flags |= SLAP_ATTR_IXADD;
+               }
        }
 
        /* check that the entry still obeys the schema */
@@ -127,24 +138,40 @@ int bdb_modify_internal(
                return rc;
        }
 
-       /* delete indices for old attributes */
-       rc = bdb_index_entry_del( be, tid, e, save_attrs);
-       if ( rc != LDAP_SUCCESS ) {
-               attrs_free( e->e_attrs );
-               e->e_attrs = save_attrs;
-               Debug( LDAP_DEBUG_ANY, "entry index delete failed!\n",
-                       0, 0, 0 );
-               return rc;
+       /* update the indices of the modified attributes */
+
+       /* start with deleting the old index entries */
+       for ( ap = save_attrs; ap != NULL; ap = ap->a_next ) {
+               if ( ap->a_flags & SLAP_ATTR_IXDEL ) {
+                       rc = bdb_index_values( be, tid, ap->a_desc, ap->a_vals,
+                                              e->e_id, SLAP_INDEX_DELETE_OP );
+                       if ( rc != LDAP_SUCCESS ) {
+                               attrs_free( e->e_attrs );
+                               e->e_attrs = save_attrs;
+                               Debug( LDAP_DEBUG_ANY,
+                                      "Attribute index delete failure",
+                                      0, 0, 0 );
+                               return rc;
+                       }
+                       ap->a_flags &= ~SLAP_ATTR_IXDEL;
+               }
        }
 
-       /* add indices for new attributes */
-       rc = bdb_index_entry_add( be, tid, e, e->e_attrs); 
-       if ( rc != LDAP_SUCCESS ) {
-               attrs_free( e->e_attrs );
-               e->e_attrs = save_attrs;
-               Debug( LDAP_DEBUG_ANY, "entry index add failed!\n",
-                       0, 0, 0 );
-               return rc;
+       /* add the new index entries */
+       for ( ap = e->e_attrs; ap != NULL; ap = ap->a_next ) {
+               if (ap->a_flags & SLAP_ATTR_IXADD) {
+                       rc = bdb_index_values( be, tid, ap->a_desc, ap->a_vals,
+                                              e->e_id, SLAP_INDEX_ADD_OP );
+                       if ( rc != LDAP_SUCCESS ) {
+                               attrs_free( e->e_attrs );
+                               e->e_attrs = save_attrs;
+                               Debug( LDAP_DEBUG_ANY,
+                                      "Attribute index add failure",
+                                      0, 0, 0 );
+                               return rc;
+                       }
+                       ap->a_flags &= ~SLAP_ATTR_IXADD;
+               }
        }
 
        return rc;
index b54e6de4c2133434aad4224e4f2b09c101e27ef1..903700600ff992f07829e223d7fbf69f7e636752 100644 (file)
@@ -207,6 +207,11 @@ ID bdb_idl_next( ID *ids, ID *cursor );
  * index.c
  */
 extern int
+bdb_index_is_indexed LDAP_P((
+       Backend *be,
+       AttributeDescription *desc ));
+
+extern int
 bdb_index_param LDAP_P((
        Backend *be,
        AttributeDescription *desc,
index 8a8f4327de6241e7d80a2642a1db2ac352d481af..bba93b59be78c5f7d864c949c62f72d4533e92eb 100644 (file)
@@ -426,6 +426,7 @@ ldap_send_entry(
                attr = (Attribute *)ch_malloc( sizeof(Attribute) );
                if (attr == NULL)
                        continue;
+               attr->a_flags = 0;
                attr->a_next = 0;
                attr->a_desc = NULL;
                if (slap_bv2ad(&mapped, &attr->a_desc, &text) != LDAP_SUCCESS) {
index cd1c685fecd34737efa8a8a92dab878de15531cb..924f16ee5764160ab38b320d5cd67e196e658edd 100644 (file)
@@ -71,6 +71,24 @@ static slap_mask_t index_mask(
        return 0;
 }
 
+int index_is_indexed(
+       Backend *be,
+       AttributeDescription *desc )
+{
+       int rc;
+       slap_mask_t mask;
+       char *dbname;
+       struct berval prefix;
+
+       mask = index_mask( be, desc, &dbname, &prefix );
+
+       if( mask == 0 ) {
+               return LDAP_INAPPROPRIATE_MATCHING;
+       }
+
+       return LDAP_SUCCESS;
+}
+
 int index_param(
        Backend *be,
        AttributeDescription *desc,
index a449f6aff291bb41873cd271753cc104505a2af1..20ef3dfee926fed33593f4aa7a2c34164a736227 100644 (file)
@@ -139,6 +139,11 @@ ID idl_nextid LDAP_P(( ID_BLOCK *idl, ID *cursor ));
  * index.c
  */
 extern int
+index_is_indexed LDAP_P((
+       Backend *be,
+       AttributeDescription *desc ));
+
+extern int
 index_param LDAP_P((
        Backend *be,
        AttributeDescription *desc,
index e47554875751c2767fad7ada2b657aa0cf25442f..259f55cab98b66adeaa75bbcca52124cf8cd326e 100644 (file)
@@ -646,6 +646,7 @@ meta_send_entry(
                if ( attr == NULL ) {
                        continue;
                }
+               attr->a_flags = 0;
                attr->a_next = 0;
                attr->a_desc = NULL;
                if ( slap_bv2ad( &mapped, &attr->a_desc, &text )
index 9af12512dcbe2f0c717e11f515c09de764bad4ea..6b17ccf018c2b679f242409129a8649403e58380 100644 (file)
@@ -625,6 +625,7 @@ int entry_decode(struct berval *bv, Entry **e)
                a->a_desc = ad;
                bptr = (BVarray)(a+1);
                a->a_vals = bptr;
+               a->a_flags = 0;
                j = entry_getlen(&ptr);
 
                while (j) {
index 1c37cec54365c67dc863ebeb3ef1887463646ccc..8accbee4252ad44d6e00797c3006b2e4376e8012 100644 (file)
@@ -27,6 +27,7 @@ slap_operational_subschemaSubentry( void )
        a->a_vals[1].bv_val = NULL;
 
        a->a_next = NULL;
+       a->a_flags = 0;
 
        return a;
 }
@@ -47,6 +48,7 @@ slap_operational_hasSubordinate( int hs )
        a->a_vals[1].bv_val = NULL;
 
        a->a_next = NULL;
+       a->a_flags = 0;
 
        return a;
 }
index e4c5abce4202a0aa385b5e3c458b1af5caca0439..26c0141b225ebfff85e5a5629d8ff25be9fd1d2c 100644 (file)
@@ -716,6 +716,9 @@ typedef struct slap_attr {
        AttributeDescription *a_desc;
        BVarray a_vals;
        struct slap_attr        *a_next;
+       unsigned a_flags;
+#define SLAP_ATTR_IXADD                0x1U
+#define SLAP_ATTR_IXDEL                0x2U
 } Attribute;