s4-ldb: added an environment varibale LDB_WARN_UNINDEXED
authorAndrew Tridgell <tridge@samba.org>
Tue, 23 Nov 2010 09:19:49 +0000 (20:19 +1100)
committerAndrew Tridgell <tridge@samba.org>
Tue, 23 Nov 2010 11:14:58 +0000 (22:14 +1100)
when LDB_WARN_UNINDEXED is set, we produce warnings about unindexed
searches. This makes it easier to find performance problems caused by
unindexed searches.

source4/lib/ldb/ABI/ldb-0.9.19.sigs
source4/lib/ldb/common/ldb_parse.c
source4/lib/ldb/include/ldb.h
source4/lib/ldb/ldb_tdb/ldb_search.c
source4/lib/ldb/ldb_tdb/ldb_tdb.c
source4/lib/ldb/ldb_tdb/ldb_tdb.h

index 53b6b2c..6273870 100644 (file)
@@ -78,7 +78,7 @@ ldb_error_at: int (struct ldb_context *, int, const char *, const char *, int)
 ldb_errstring: const char *(struct ldb_context *)
 ldb_extended: int (struct ldb_context *, const char *, void *, struct ldb_result **)
 ldb_extended_default_callback: int (struct ldb_request *, struct ldb_reply *)
-ldb_filter_from_tree: char *(TALLOC_CTX *, struct ldb_parse_tree *)
+ldb_filter_from_tree: char *(TALLOC_CTX *, const struct ldb_parse_tree *)
 ldb_get_config_basedn: struct ldb_dn *(struct ldb_context *)
 ldb_get_create_perms: unsigned int (struct ldb_context *)
 ldb_get_default_basedn: struct ldb_dn *(struct ldb_context *)
index 16b3e21..b4eabf8 100644 (file)
@@ -679,7 +679,7 @@ struct ldb_parse_tree *ldb_parse_tree(TALLOC_CTX *mem_ctx, const char *s)
 /*
   construct a ldap parse filter given a parse tree
 */
-char *ldb_filter_from_tree(TALLOC_CTX *mem_ctx, struct ldb_parse_tree *tree)
+char *ldb_filter_from_tree(TALLOC_CTX *mem_ctx, const struct ldb_parse_tree *tree)
 {
        char *s, *s2, *ret;
        unsigned int i;
index eeb939a..1deed84 100644 (file)
@@ -314,7 +314,7 @@ struct ldb_parse_tree {
 };
 
 struct ldb_parse_tree *ldb_parse_tree(TALLOC_CTX *mem_ctx, const char *s);
-char *ldb_filter_from_tree(TALLOC_CTX *mem_ctx, struct ldb_parse_tree *tree);
+char *ldb_filter_from_tree(TALLOC_CTX *mem_ctx, const struct ldb_parse_tree *tree);
 
 /**
    Encode a binary blob
index 5df1e4d..b58243c 100644 (file)
@@ -578,13 +578,13 @@ int ltdb_search(struct ltdb_context *ctx)
                 * callback error */
                if ( ! ctx->request_terminated && ret != LDB_SUCCESS) {
                        /* Not indexed, so we need to do a full scan */
-#if 0
-                       /* useful for debugging when slow performance
-                        * is caused by unindexed searches */
-                       char *expression = ldb_filter_from_tree(ctx, ctx->tree);
-                       printf("FULL SEARCH: %s\n", expression);
-                       talloc_free(expression);
-#endif
+                       if (ltdb->warn_unindexed) {
+                               /* useful for debugging when slow performance
+                                * is caused by unindexed searches */
+                               char *expression = ldb_filter_from_tree(ctx, ctx->tree);
+                               ldb_debug(ldb, LDB_DEBUG_WARNING, "ldb FULL SEARCH: %s\n", expression);
+                               talloc_free(expression);
+                       }
                        if (match_count != 0) {
                                /* the indexing code gave an error
                                 * after having returned at least one
index 2e88989..066d408 100644 (file)
@@ -1463,6 +1463,10 @@ static int ltdb_connect(struct ldb_context *ldb, const char *url,
                return LDB_ERR_OPERATIONS_ERROR;
        }
 
+       if (getenv("LDB_WARN_UNINDEXED")) {
+               ltdb->warn_unindexed = true;
+       }
+
        ltdb->sequence_number = 0;
 
        module = ldb_module_new(ldb, ldb, "ldb_tdb backend", &ltdb_ops);
index 493c276..33313b0 100644 (file)
@@ -34,6 +34,8 @@ struct ltdb_private {
        struct ltdb_idxptr *idxptr;
        bool prepared_commit;
        int read_lock_count;
+
+       bool warn_unindexed;
 };
 
 /*