Skip to content

Tracking zero counts #5114

@mehdiym

Description

@mehdiym

Hello,

When using the count index at the query root, I regularly need to get values lower than a threshold, including zero.

For instance, suppose I have products connected to suppliers and I’d like to known when there are not enough suppliers. I could use the following query:

{
  me(func:lt(count(supplier), 3)) {
    uid
    product_name
  }
}

But I will miss the products with 0 suppliers: the most important ones to me.

I could use a second query block with a filter not has(supplier) but it is no efficient as not using any index.

What about adding an option on @count index to also track 0 counts?
It could be tracked only for the types containing the predicates with those indexes.

For example :

type Product {
  supplier
}
supplier: [uid] @count(zero) .

Original forum thread: https://discuss.dgraph.io/t/tracking-zero-counts/6235

Metadata

Metadata

Assignees

No one assigned

    Labels

    area/indexesRelated to indexes (indices) and their usage.area/querylangIssues related to the query language specification and implementation.priority/P3Low priority, something to be done once everything else seems fixed.status/acceptedWe accept to investigate/work on it.status/needs-attentionThis issue needs more eyes on it, more investigation might be required before accepting/rejecting it

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions