Push down optimization for group by statement

Hi Team,

I am working on query optimization for one of my query . I am trying to push down the group by operation to be performed by the index node rather than query node.

I have given the info needed below.

Primary key : EMP:ACCT#1
document:
{
“name”: “user1”,
“type”: “ACCOUNTS_EMPLOYEE”,
“age”: 27,
“title”: “SENIOR_ACCOUNTANT”
}

Index:
CREATE INDEX emp_bucket_acct_emp ON EMP_BUCKET(title,name,age) WHERE (type = “ACCOUNTS_EMPLOYEE”)

$names is just a variable.

When the condition is c.name = $names , the group by is performed by index node but when I use AND c.name in $names , the group by is performed by query node.

SELECT c.title,
COUNT(title) AS count
FROM BNE_TRAFFIC AS c
WHERE c.type=“ACCOUNTS_EMPLOYEE”
AND c.title IS NOT MISSING
AND c.name = $names
AND c.age >= 28
AND c.age <= 45
GROUP BY title

SELECT c.title,
COUNT(title) AS count
FROM BNE_TRAFFIC AS c
WHERE c.type=“ACCOUNTS_EMPLOYEE”
AND c.title IS NOT MISSING
AND c.name in $names
AND c.age >= 28
AND c.age <= 45
GROUP BY title

Kindly let me know how to make the index node do the group by in case of above query.

Or if this is not possible, how to change the IN condition so as to make the above optimization possible

Index aggregation possible only when all predicates pushed to indexer, no false positives from indexer and query covered.

When you have AND c.name in $names we don’t know how many elements in $names during prepared time.
(check IN List Handling Improvements in Couchbase Server 6.5 | The Couchbase Blog), when inlist is execeed 8192 false positives possible.

If you have the inlist is fixed and few use [$name1,$name2,$name3] . In case if you used 3 but have only one set name2, anmes3 same as name1
Other options is use adhoc=True i.e non prepared statements.