ldb: Allow a caller (in particular Samba) to handle the list of attributes with an...
authorAndrew Bartlett <abartlet@samba.org>
Thu, 30 Mar 2017 00:23:44 +0000 (13:23 +1300)
committerAndrew Bartlett <abartlet@samba.org>
Wed, 31 May 2017 04:34:26 +0000 (06:34 +0200)
By doing that, Samba will use a binary search to locate the attributes
rather than an O(n) search, during every search or modify of the database.

Signed-off-by: Andrew Bartlett <abartlet@samba.org>
Reviewed-by: Stefan Metzmacher <metze@samba.org>
Reviewed-by: Garming Sam <garming@catalyst.net.nz>
lib/ldb/ABI/ldb-1.1.29.sigs
lib/ldb/common/ldb_attributes.c
lib/ldb/include/ldb.h
lib/ldb/include/ldb_module.h
lib/ldb/include/ldb_private.h
lib/ldb/ldb_tdb/ldb_index.c

index 0ea968d0d69cd70d5f0b938393570699ae48a97e..9b865ed89074f399a8d8fd8ce17b981dbe621629 100644 (file)
@@ -225,6 +225,7 @@ ldb_schema_attribute_fill_with_syntax: int (struct ldb_context *, TALLOC_CTX *,
 ldb_schema_attribute_remove: void (struct ldb_context *, const char *)
 ldb_schema_attribute_remove_flagged: void (struct ldb_context *, unsigned int)
 ldb_schema_attribute_set_override_handler: void (struct ldb_context *, ldb_attribute_handler_override_fn_t, void *)
+ldb_schema_set_override_indexlist: void (struct ldb_context *, bool)
 ldb_search: int (struct ldb_context *, TALLOC_CTX *, struct ldb_result **, struct ldb_dn *, enum ldb_scope, const char * const *, const char *, ...)
 ldb_search_default_callback: int (struct ldb_request *, struct ldb_reply *)
 ldb_sequence_number: int (struct ldb_context *, enum ldb_sequence_type, uint64_t *)
index 2021a0bf64aac5f7fda0090280bcf8cf622ffa43..98ec5a409ba0eeabc57a0f0484b34931936f9f58 100644 (file)
@@ -383,3 +383,15 @@ void ldb_schema_attribute_set_override_handler(struct ldb_context *ldb,
        ldb->schema.attribute_handler_override_private = private_data;
        ldb->schema.attribute_handler_override = override;
 }
+
+/*
+  set that the attribute handler override function - used to delegate
+  schema handling to external code, is handling setting
+  LDB_ATTR_FLAG_INDEXED
+ */
+void ldb_schema_set_override_indexlist(struct ldb_context *ldb,
+                                      bool one_level_indexes)
+{
+       ldb->schema.index_handler_override = true;
+       ldb->schema.one_level_indexes = one_level_indexes;
+}
index 1160a48cc06d1ee487a106400e26dc278f791a7b..3fab929ff5e432eaf592754e4f4d4bac30a4fe9f 100644 (file)
@@ -441,6 +441,11 @@ const struct ldb_dn_extended_syntax *ldb_dn_extended_syntax_by_name(struct ldb_c
  */
 #define LDB_ATTR_FLAG_FROM_DB      (1<<6)
 
+/*
+ * The attribute was loaded from a DB, rather than via the C API
+ */
+#define LDB_ATTR_FLAG_INDEXED      (1<<7)
+
 /**
   LDAP attribute syntax for a DN
 
index 833d5a8f3d07d380ff030e0943b8884f070aa468..75f3fcb2bf8a8dc7274ac64f1a1657744c2c254b 100644 (file)
@@ -125,6 +125,8 @@ typedef const struct ldb_schema_attribute *(*ldb_attribute_handler_override_fn_t
 void ldb_schema_attribute_set_override_handler(struct ldb_context *ldb,
                                               ldb_attribute_handler_override_fn_t override,
                                               void *private_data);
+void ldb_schema_set_override_indexlist(struct ldb_context *ldb,
+                                      bool one_level_indexes);
 
 /* A useful function to build comparison functions with */
 int ldb_any_comparison(struct ldb_context *ldb, void *mem_ctx, 
index 644d49cd23f6ad747cdd8310c1538dc9b5837dfa..bd975b81fecb7c5a73400e136f508f2895989dbd 100644 (file)
@@ -88,6 +88,13 @@ struct ldb_schema {
 
        unsigned num_dn_extended_syntax;
        struct ldb_dn_extended_syntax *dn_extended_syntax;
+
+       /*
+        * If set, the attribute_handler_override has the details of
+        * what attributes have an index
+        */
+       bool index_handler_override;
+       bool one_level_indexes;
 };
 
 /*
index 46ba725c07f977c4bbdd508bce6cebb46119a065..721ec1c9a6a9a4d32d17879690a8aa72c2c4881f 100644 (file)
@@ -449,9 +449,25 @@ static bool ltdb_is_indexed(struct ldb_module *module,
                            struct ltdb_private *ltdb,
                            const char *attr)
 {
+       struct ldb_context *ldb = ldb_module_get_ctx(module);
        unsigned int i;
        struct ldb_message_element *el;
 
+       if (ldb->schema.index_handler_override) {
+               const struct ldb_schema_attribute *a
+                       = ldb_schema_attribute_by_name(ldb, attr);
+
+               if (a == NULL) {
+                       return false;
+               }
+
+               if (a->flags & LDB_ATTR_FLAG_INDEXED) {
+                       return true;
+               } else {
+                       return false;
+               }
+       }
+
        if (!ltdb->cache->attribute_indexes) {
                return false;
        }