summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorTim Beale <timbeale@catalyst.net.nz>2019-02-04 10:49:03 +1300
committerStefan Metzmacher <metze@samba.org>2019-02-13 15:01:18 +0100
commitbefb3527bc2c94763d5daf57afa7ad5e94c929da (patch)
tree8b76399d58ca53c8af4afa5008b4d1ceb7c3fcd5 /lib
parent9b21b518d7264cb1e1fddfeea440fb70d0bc8e50 (diff)
downloadsamba-befb3527bc2c94763d5daf57afa7ad5e94c929da.tar.gz
ldb: Avoid inefficient one-level searches
Commit 88ae60ed186c9 introduced a problem that made one-level searches inefficient if there were a lot of child objects in the same level, and the requested object didn't exist. Basically, it ignored the case where ldb_kv_index_dn() returned LDB_ERR_NO_SUCH_OBJECT, i.e. the indexed lookup was successful, but didn't find a match. At which point, there was no more processing we needed to do. The behaviour after 88ae60ed186c9 was to fall-through and run the ldb_kv_index_filter() function over *all* the children. This still returned the correct result, but could be costly if there were a lot of children. The case 88ae60ed186c9 was trying to fix was where we could not do an indexed search (e.g. trying to match on a 'attribute=*' filter). In which case we want to ignore the LDB_ERR_OPERATIONS_ERROR and just run ldb_kv_index_filter() over all the children. This is still more efficient than the fallback of doing a full database scan. This patch adds in a short-circuit for the NO_SUCH_OBJECT case, so we can skip the unnecessary ldb_kv_index_filter() work. BUG: https://bugzilla.samba.org/show_bug.cgi?id=13762 Signed-off-by: Tim Beale <timbeale@catalyst.net.nz> Reviewed-by: Andrew Bartlett <abartlet@samba.org> (Manual merge of commit 9a893f9613bd6440ab in master)
Diffstat (limited to 'lib')
-rw-r--r--lib/ldb/ldb_tdb/ldb_index.c18
1 files changed, 14 insertions, 4 deletions
diff --git a/lib/ldb/ldb_tdb/ldb_index.c b/lib/ldb/ldb_tdb/ldb_index.c
index 4b5054e81ec..55abcba6b74 100644
--- a/lib/ldb/ldb_tdb/ldb_index.c
+++ b/lib/ldb/ldb_tdb/ldb_index.c
@@ -2031,13 +2031,23 @@ int ltdb_search_indexed(struct ltdb_context *ac, uint32_t *match_count)
}
/*
* Here we load the index for the tree.
- *
- * We only care if this is successful, if the
- * index can't trim the result list down then
- * the ONELEVEL index is still good enough.
*/
ret = ltdb_index_dn(ac->module, ltdb, ac->tree,
idx_one_tree_list);
+
+ /*
+ * We can stop if we're sure the object doesn't exist
+ */
+ if (ret == LDB_ERR_NO_SUCH_OBJECT) {
+ talloc_free(idx_one_tree_list);
+ talloc_free(dn_list);
+ return LDB_ERR_NO_SUCH_OBJECT;
+ }
+
+ /* We only care if this is successful, if the
+ * index can't trim the result list down then
+ * the ONELEVEL index is still good enough.
+ */
if (ret == LDB_SUCCESS) {
if (!list_intersect(ldb, ltdb,
dn_list,