redis / redis/redis-om-python

Review count() implementation - consider FT.AGGREGATE

Open
#744 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

enhancement performance
Dominant language
Python
Stars
1.3k
Forks
128
PR merge metrics
No merged PRs in 30d

Description

Summary

The current FindQuery.count() implementation uses FT.SEARCH with LIMIT 0 0 and nocontent=True:

async def count(self):
    query = self.copy(offset=0, limit=0, nocontent=True)
    result = await query.execute(exhaust_results=True, return_raw_result=True)
    return result[0]

This works, but FT.AGGREGATE with a count reducer may be a better approach.

Why FT.AGGREGATE might be better

  1. Purpose-built for aggregations - FT.AGGREGATE is designed for operations like counting, grouping, etc.
  2. More flexible - Could support count() with grouping (e.g., count by category)
  3. Potentially more efficient - Aggregation pipeline is optimized for this use case

Example with FT.AGGREGATE

FT.AGGREGATE idx * GROUPBY 0 REDUCE COUNT 0 AS total

This returns just the count without any document data.

Tasks

  • Benchmark current FT.SEARCH LIMIT 0 0 vs FT.AGGREGATE for count
  • Evaluate if FT.AGGREGATE provides any performance benefits
  • Consider adding grouped count support (e.g., Model.find().count(group_by="category"))

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start at the FindQuery.count() implementation shown in the issue and review how it currently executes FT.SEARCH. Benchmark that approach against the proposed FT.AGGREGATE count, then assess whether grouped counts should be included. Done means the performance comparison and implementation scope have a documented conclusion.

Written by the indexing model from the issue text.

Assessment

Tech stack
python, redis
Domain
databases
Issue type
Refactor
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.