ldb: Avoid inefficient one-level searches
authorTim Beale <timbeale@catalyst.net.nz>
Thu, 10 Jan 2019 00:34:18 +0000 (13:34 +1300)
committerStefan Metzmacher <metze@samba.org>
Wed, 13 Feb 2019 10:41:10 +0000 (11:41 +0100)
commit7fc3481765720d2fa0324f297e4a658520fb092f
tree7d6fad28f826560a15e283c6606116eaa4f1d899
parent0c75bfe674b9e2d3fc9671fb85b334c0a392e13d
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>
(cherry picked from commit 9a893f9613bd6440abd8e487d22a39ab5b82a7b9)
lib/ldb/ldb_key_value/ldb_kv_index.c