RediSearch / RediSearch

A query and indexing engine for Redis, providing secondary indexing, full-text search, vector similarity search and aggregations.
https://redis.io/docs/stack/search/
Other
5.47k stars 519 forks source link

Potential performance improvement on tag prefix search #1436

Open MeirShpilraien opened 4 years ago

MeirShpilraien commented 4 years ago

On Query_EvalTagPrefixNode we do the prefix search on the trie, once we find a match we search for the term in the trie again though we already have the value (the prefix iterator returns it):

// Find all completions of the prefix
  size_t maxExpansions = q->sctx->spec->maxPrefixExpansions;
  while (TrieMapIterator_Next(it, &s, &sl, &ptr) &&
         (itsSz < maxExpansions || maxExpansions == -1)) {
    IndexIterator *ret = TagIndex_OpenReader(idx, q->sctx->spec, s, sl, 1);
    if (!ret) continue;

    // Add the reader to the iterator array
    its[itsSz++] = ret;
    if (itsSz == itsCap) {
      itsCap *= 2;
      its = rm_realloc(its, itsCap * sizeof(*its));
    }
  }

The TagIndex_OpenReader performce another lookup on the trie and get the pointer which we already have on ptr variable.

ashtul commented 4 years ago

@MeirShpilraien Just tested at 4b76c9e93b8d9dcfceb17cd37823ec0ecc61c3bb It causes test testPrefixDeletedExpansions to fail. Tests 'ft.search idx "@txt1:term* @tag1:{tag*}"

ashtul commented 3 years ago

Delete branch performance-imp-for-Query_EvalTagPrefixNode once close this issue.