astdb: Improve prefix searches in astdb

Using the LIKE operator requires a full table scan of 'astdb', whereas a
comparison operation is able to use the primary key index.

This patch adds a new function to the AstDB API for quick prefix matches
and updates res_sorcery_astdb to utilize it. This showed substantial
performance improvement in my test environment.

Related to ASTERISK~26806, but does not completely resolve it.

Change-Id: I7d37f9ba2aea139dabf2ca72d31fbe34bd9b2fa1
This commit is contained in:
Sean Bright
2017-12-07 15:19:40 -05:00
parent b0b28446c1
commit 9a9edc6c9e
3 changed files with 107 additions and 30 deletions

View File

@@ -334,14 +334,14 @@ static void sorcery_astdb_retrieve_prefix(const struct ast_sorcery *sorcery, voi
const char *family_prefix = data;
size_t family_len = strlen(family_prefix) + strlen(type) + 1; /* +1 for slash delimiter */
char family[family_len + 1];
char tree[prefix_len + sizeof("%")];
char tree[prefix_len + 1];
RAII_VAR(struct ast_db_entry *, entries, NULL, ast_db_freetree);
struct ast_db_entry *entry;
snprintf(tree, sizeof(tree), "%.*s%%", (int) prefix_len, prefix);
snprintf(tree, sizeof(tree), "%.*s", (int) prefix_len, prefix);
snprintf(family, sizeof(family), "%s/%s", family_prefix, type);
if (!(entries = ast_db_gettree(family, tree))) {
if (!(entries = ast_db_gettree_by_prefix(family, tree))) {
return;
}