]> git.sur5r.net Git - openldap/commitdiff
Add DN_INDICES search filter and has_children support. Move id2children
authorKurt Zeilenga <kurt@openldap.org>
Fri, 13 Aug 1999 00:55:08 +0000 (00:55 +0000)
committerKurt Zeilenga <kurt@openldap.org>
Fri, 13 Aug 1999 00:55:08 +0000 (00:55 +0000)
behind -UDN_INDICES.

servers/slapd/back-ldbm/add.c
servers/slapd/back-ldbm/back-ldbm.h
servers/slapd/back-ldbm/delete.c
servers/slapd/back-ldbm/dn2id.c
servers/slapd/back-ldbm/filterindex.c
servers/slapd/back-ldbm/id2children.c
servers/slapd/back-ldbm/init.c
servers/slapd/back-ldbm/proto-back-ldbm.h
servers/slapd/back-ldbm/search.c
servers/slapd/slap.h
servers/slapd/tools/ldif2id2children.c

index 0333fe412930907b15f0f1f0bb8d703a1c6dd894..b6679f1994a525d8f484ae02a3c4b1122719d94d 100644 (file)
@@ -226,10 +226,10 @@ ldbm_back_add(
 
        rc = -1;
 
+#ifndef DN_INDICES
        /*
         * add it to the id2children index for the parent
         */
-
        if ( id2children_add( be, p, e ) != 0 ) {
                Debug( LDAP_DEBUG_TRACE, "id2children_add failed\n", 0,
                    0, 0 );
@@ -238,6 +238,7 @@ ldbm_back_add(
 
                goto return_results;
        }
+#endif
 
        /*
         * Add the entry to the attribute indexes, then add it to
index 377c8389f83e46f90db0b68cb4942705882f1368..fac176726e3264b73ee854cba14f0003343a32d9 100644 (file)
@@ -25,9 +25,12 @@ LDAP_BEGIN_DECL
 #define SUBLEN                 3
 
 /* #undef DN_INDICES *//* generate dn eq, subtree, and parent indices */
-#define DN_ENTRY_PREFIX                '='
+#define DN_BASE_PREFIX         '='
+#define DN_ONE_PREFIX          '@'
 #define DN_SUBTREE_PREFIX      '?'
-#define DN_PARENT_PREFIX       '@'
+
+#define SLAPD_FILTER_DN_ONE            ((ber_tag_t) -2)
+#define SLAPD_FILTER_DN_SUBTREE        ((ber_tag_t) -3)
 
 /*
  * there is a single index for each attribute.  these prefixes ensure
@@ -111,12 +114,12 @@ typedef struct ldbm_dbcache {
 typedef struct ldbm_attrinfo {
        char    *ai_type;       /* type name (cn, sn, ...)      */
        int     ai_indexmask;   /* how the attr is indexed      */
-#define INDEX_PRESENCE 0x01
-#define INDEX_EQUALITY 0x02
-#define INDEX_APPROX   0x04
-#define INDEX_SUB      0x08
-#define INDEX_UNKNOWN  0x10
-#define INDEX_FROMINIT 0x20
+#define INDEX_PRESENCE         0x0001
+#define INDEX_EQUALITY         0x0002
+#define INDEX_APPROX           0x0004
+#define INDEX_SUB                      0x0008
+#define INDEX_UNKNOWN          0x0010
+#define INDEX_FROMINIT         0x1000
        int     ai_syntaxmask;  /* what kind of syntax          */
 /* ...from slap.h...
 #define SYNTAX_CIS      0x01
index a8180b3cf16570a17ce6e0fb35f64457a61f3f73..ac6b7d6343e1d089c1d524f880f52ad6f0ec1d70 100644 (file)
@@ -140,6 +140,7 @@ ldbm_back_delete(
                rootlock = 1;
        }
 
+#ifndef DN_INDICES
        if ( id2children_remove( be, p, e ) != 0 ) {
                Debug(LDAP_DEBUG_ARGS,
                        "<=- ldbm_back_delete: operations error %s\n",
@@ -148,6 +149,7 @@ ldbm_back_delete(
                        NULL, NULL, NULL, NULL );
                goto return_results;
        }
+#endif
 
        /* delete from dn2id mapping */
        if ( dn2id_delete( be, e->e_ndn ) != 0 ) {
index c82ffb25760f94235f092afe0ab2dbfa43b77758..1353146f4a21055ca29a121cba681e761989b764 100644 (file)
@@ -45,7 +45,7 @@ dn2id_add(
 #else
        key.dsize = strlen( dn ) + 2;
        key.dptr = ch_malloc( key.dsize );
-       sprintf( key.dptr, "%c%s", DN_ENTRY_PREFIX, dn );
+       sprintf( key.dptr, "%c%s", DN_BASE_PREFIX, dn );
 #endif
 
        data.dptr = (char *) &id;
@@ -65,7 +65,7 @@ dn2id_add(
                if( pdn != NULL ) {
                        key.dsize = strlen( pdn ) + 2;
                        key.dptr = ch_malloc( key.dsize );
-                       sprintf( key.dptr, "%c%s", DN_PARENT_PREFIX, pdn );
+                       sprintf( key.dptr, "%c%s", DN_ONE_PREFIX, pdn );
                        rc = idl_insert_key( be, db, key, id );
                        free( key.dptr );
                }
@@ -131,48 +131,13 @@ dn2id(
                return( NOID );
        }
 
-#ifdef DN_INDICES
-       {
-               char *pdn = dn_parent( NULL, dn );
-
-               if( pdn != NULL ) {
-                       key.dsize = strlen( pdn ) + 2;
-                       key.dptr = ch_malloc( key.dsize );
-                       sprintf( key.dptr, "%c%s", DN_PARENT_PREFIX, pdn );
-                       (void) idl_delete_key( be, db, key, id );
-                       free( key.dptr );
-               }
-
-       }
-
-       {
-               char **subtree = dn_subtree( NULL, dn );
-
-               if( subtree != NULL ) {
-                       int i;
-                       for( i=0; subtree[i] != NULL; i++ ) {
-                               key.dsize = strlen( dn ) + 2;
-                               key.dptr = ch_malloc( key.dsize );
-                               sprintf( key.dptr, "%c%s", DN_SUBTREE_PREFIX, dn );
-
-                               (void) idl_delete_key( be, db, key, id );
-
-                               free( key.dptr );
-                       }
-
-                       charray_free( subtree );
-               }
-
-       }
-#endif
-
 #ifndef DN_INDICES
        key.dptr = dn;
        key.dsize = strlen( key.dptr ) + 1;
 #else
        key.dsize = strlen( dn ) + 2;
        key.dptr = ch_malloc( key.dsize );
-       sprintf( key.dptr, "%c%s", DN_ENTRY_PREFIX, dn );
+       sprintf( key.dptr, "%c%s", DN_BASE_PREFIX, dn );
 #endif
 
        data = ldbm_cache_fetch( db, key );
@@ -196,6 +161,43 @@ dn2id(
        return( id );
 }
 
+#ifdef DN_INDICES
+ID_BLOCK *
+dn2idl(
+    Backend    *be,
+    char       *dn,
+       int             prefix
+)
+{
+       DBCache *db;
+       Datum           key;
+       ID_BLOCK        *idl;
+
+       ldbm_datum_init( key );
+
+       Debug( LDAP_DEBUG_TRACE, "=> dn2idl( \"%c%s\" )\n", prefix, dn, 0 );
+
+       if ( (db = ldbm_cache_open( be, "dn2id", LDBM_SUFFIX, LDBM_WRCREAT ))
+               == NULL ) {
+               Debug( LDAP_DEBUG_ANY, "<= dn2idl could not open dn2id%s\n",
+                       LDBM_SUFFIX, 0, 0 );
+               return NULL;
+       }
+
+       key.dsize = strlen( dn ) + 2;
+       key.dptr = ch_malloc( key.dsize );
+       sprintf( key.dptr, "%c%s", prefix, dn );
+
+       idl = idl_fetch( be, db, key );
+
+       ldbm_cache_close( be, db );
+
+       free( key.dptr );
+
+       return( idl );
+}
+#endif
+
 int
 dn2id_delete(
     Backend    *be,
@@ -224,7 +226,7 @@ dn2id_delete(
 #else
        key.dsize = strlen( dn ) + 2;
        key.dptr = ch_malloc( key.dsize );
-       sprintf( key.dptr, "%c%s", DN_ENTRY_PREFIX, dn );
+       sprintf( key.dptr, "%c%s", DN_BASE_PREFIX, dn );
 #endif
 
        rc = ldbm_cache_delete( db, key );
index 074872e6420e00ef873be6fb42da2d1167e24db3..370dc230ab32217497366c770413fcf0e8c658df 100644 (file)
@@ -40,6 +40,17 @@ filter_candidates(
 
        result = NULL;
        switch ( f->f_choice ) {
+#ifdef DN_INDICES
+       case SLAPD_FILTER_DN_ONE:
+               Debug( LDAP_DEBUG_FILTER, "\tDN ONE\n", 0, 0, 0 );
+               result = dn2idl( be, f->f_dn, DN_ONE_PREFIX );
+               break;
+
+       case SLAPD_FILTER_DN_SUBTREE:
+               Debug( LDAP_DEBUG_FILTER, "\tDN SUBTREE\n", 0, 0, 0 );
+               result = dn2idl( be, f->f_dn, DN_SUBTREE_PREFIX );
+               break;
+#endif
        case LDAP_FILTER_EQUALITY:
                Debug( LDAP_DEBUG_FILTER, "\tEQUALITY\n", 0, 0, 0 );
                result = ava_candidates( be, &f->f_ava, LDAP_FILTER_EQUALITY );
index 34eeafdf6d7698a9de871af7cce2b9fab0b6d1ea..c5bc3f052402b2c4a30d44773c8548f1f5b57038 100644 (file)
@@ -14,6 +14,7 @@
 #include "slap.h"
 #include "back-ldbm.h"
 
+#ifndef DN_INDICES
 int
 id2children_add(
     Backend    *be,
@@ -102,6 +103,7 @@ id2children_remove(
        Debug( LDAP_DEBUG_TRACE, "<= id2children_remove 0\n", 0, 0, 0 );
        return( 0 );
 }
+#endif
 
 int
 has_children(
@@ -113,12 +115,15 @@ has_children(
        Datum           key;
        int             rc = 0;
        ID_BLOCK                *idl;
+#ifndef DN_INDICES
        char            buf[20];
+#endif
 
        ldbm_datum_init( key );
 
        Debug( LDAP_DEBUG_TRACE, "=> has_children( %ld )\n", p->e_id , 0, 0 );
 
+#ifndef DN_INDICES
        if ( (db = ldbm_cache_open( be, "id2children", LDBM_SUFFIX,
            LDBM_WRCREAT )) == NULL ) {
                Debug( LDAP_DEBUG_ANY,
@@ -131,6 +136,20 @@ has_children(
        key.dptr = buf;
        key.dsize = strlen( buf ) + 1;
 
+#else
+       if ( (db = ldbm_cache_open( be, "dn2id", LDBM_SUFFIX,
+           LDBM_WRCREAT )) == NULL ) {
+               Debug( LDAP_DEBUG_ANY,
+                   "<= has_children -1 could not open \"dn2id%s\"\n",
+                   LDBM_SUFFIX, 0, 0 );
+               return( 0 );
+       }
+
+       key.dsize = strlen( p->e_ndn ) + 2;
+       key.dptr = ch_malloc( key.dsize );
+       sprintf( key.dptr, "%c%s", DN_ONE_PREFIX, p->e_ndn );
+#endif
+
        idl = idl_fetch( be, db, key );
 
        ldbm_cache_close( be, db );
index 79c1974269ef443a28f936230870d7dde44162c6..bc61fe9ccb94c82fc870f3b55f1d23692d0f98cc 100644 (file)
@@ -128,6 +128,7 @@ ldbm_back_db_init(
        /* default database directory */
        li->li_directory = ch_strdup( DEFAULT_DB_DIRECTORY );
 
+#ifndef DN_INDICES
        /* always index dn, id2children, objectclass (used in some searches) */
        if ( !at_find( "dn" ) ) {
                argv[ 0 ] = "dn";
@@ -144,6 +145,7 @@ ldbm_back_db_init(
        argv[ 2 ] = NULL;
        attr_index_config( li, "ldbm id2children initialization", 0, 2, argv,
            1 );
+#endif
        argv[ 0 ] = "objectclass";
        argv[ 1 ] = "pres,eq";
        argv[ 2 ] = NULL;
index f490e321ce405c2438690d71aaf4efba005afad8..341a09ead25f8264d61e46fd7e1debf57b3f1ab2 100644 (file)
@@ -76,6 +76,7 @@ int ldbm_cache_delete LDAP_P(( DBCache *db, Datum key ));
 
 int dn2id_add LDAP_P(( Backend *be, char *dn, ID id ));
 ID dn2id LDAP_P(( Backend *be, char *dn ));
+ID_BLOCK *dn2idl LDAP_P(( Backend *be, char *dn, int prefix ));
 int dn2id_delete LDAP_P(( Backend *be, char *dn ));
 
 Entry * dn2entry_rw LDAP_P(( Backend *be, char *dn, Entry **matched, int rw ));
index 9589c2fd9cc8d3e28d3dcb10d4c498e113ca5f36..6c2cc6169c708967c434b0b251b9774a51eed92e 100644 (file)
@@ -400,28 +400,40 @@ search_candidates(
                lf->f_choice = LDAP_FILTER_AND;
                lf->f_and = (Filter *) ch_malloc( sizeof(Filter) );
 
+#ifndef DN_INDICES
                lf->f_and->f_choice = LDAP_FILTER_SUBSTRINGS;
                lf->f_and->f_sub_type = ch_strdup( "dn" );
                lf->f_and->f_sub_initial = NULL;
                lf->f_and->f_sub_any = NULL;
                lf->f_and->f_sub_final = ch_strdup( e->e_ndn );
+#else
+               lf->f_and->f_choice = SLAPD_FILTER_DN_SUBTREE;
+               lf->f_and->f_dn = e->e_ndn;
+#endif
 
                lf->f_and->f_next = f;
                f = lf;
 
        } else if ( scope == LDAP_SCOPE_ONELEVEL ) {
+#ifndef DN_INDICES
                char buf[16];
+#endif
 
                lf = (Filter *) ch_malloc( sizeof(Filter) );
                lf->f_next = NULL;
                lf->f_choice = LDAP_FILTER_AND;
                lf->f_and = (Filter *) ch_malloc( sizeof(Filter) );
 
+#ifndef DN_INDICES
                lf->f_and->f_choice = LDAP_FILTER_EQUALITY;
                lf->f_and->f_ava.ava_type = ch_strdup( "id2children" );
                sprintf( buf, "%ld", e != NULL ? e->e_id : 0 );
                lf->f_and->f_ava.ava_value.bv_val = ch_strdup( buf );
                lf->f_and->f_ava.ava_value.bv_len = strlen( buf );
+#else
+               lf->f_and->f_choice = SLAPD_FILTER_DN_ONE;
+               lf->f_and->f_dn = e->e_ndn;
+#endif
 
                lf->f_and->f_next = f;
                f = lf;
@@ -434,8 +446,13 @@ search_candidates(
 
        /* free up filter additions we allocated above */
        if( lf != NULL ) {
+#ifndef DN_INDICES
                lf->f_and->f_next = NULL;
                filter_free( lf );
+#else
+               free( lf->f_and );
+               free( lf );
+#endif
        }
 
        if( af != NULL ) {
index 56e732d5e452606182c646c4cd1e64628fc7bb12..4792c0bb418109924d9008c5c2d23ff52f77ddd4 100644 (file)
@@ -149,6 +149,8 @@ typedef struct slap_filter {
                        char    *f_un_sub_final;
                } f_un_sub;
        } f_un;
+
+#define f_dn           f_un.f_un_type  /* used for DN indices */
 #define f_type         f_un.f_un_type
 #define f_ava          f_un.f_un_ava
 #define f_avtype       f_un.f_un_ava.ava_type
index 180002e8dca9615ddf78a56637f0e7cc0e5b74e6..ae07c18d83a810fbd7c3236b4ed84ae29039dcb6 100644 (file)
@@ -24,7 +24,10 @@ main( int argc, char **argv )
        int             lineno, elineno;
        int         lmax;
        ID              id;
-       DBCache *db, *db2;
+       DBCache *db;
+#ifndef DN_INDICES
+       DBCache *db2;
+#endif
        Backend         *be = NULL;
        struct ldbminfo *li;
        struct berval   bv;
@@ -92,7 +95,7 @@ main( int argc, char **argv )
 #else
                                        key.dsize = strlen( val ) + 2;
                                        key.dptr = ch_malloc( key.dsize );
-                                       sprintf( key.dptr, "%c%s", DN_ENTRY_PREFIX, val );
+                                       sprintf( key.dptr, "%c%s", DN_BASE_PREFIX, val );
 #endif
                                        data.dptr = (char *) &id;
                                        data.dsize = sizeof(ID);
@@ -112,7 +115,7 @@ main( int argc, char **argv )
                                                        key.dsize = strlen( pdn ) + 2;
                                                        key.dptr = ch_malloc( key.dsize );
                                                        sprintf( key.dptr, "%c%s",
-                                                               DN_PARENT_PREFIX, pdn );
+                                                               DN_ONE_PREFIX, pdn );
                                                        rc = idl_insert_key( be, db, key, id );
                                                        free( key.dptr );
                                                }
@@ -155,6 +158,8 @@ main( int argc, char **argv )
        if ( buf )
                free( buf );
 
+
+#ifndef DN_INDICES
        /*
         * next, make the id2children index
         */
@@ -240,6 +245,12 @@ main( int argc, char **argv )
        ldbm_cache_close( be, db2 );
        ldbm_cache_close( be, db );
 #endif
+#else
+#ifdef SLAP_CLEANUP
+       ldbm_cache_close( be, db );
+#endif
+#endif
+
 
        slap_shutdown(dbnum);
        slap_destroy();