graphprotocol / graphprotocol/graph-node

[Bug] Ordering by children can be nondeterministic

Open
#5,359 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug Stale
Dominant language
Rust
Stars
3.2k
Forks
1.1k
Avg merge
4d 1h
Merged PRs (30d)
1

Description

Bug report

With a schema like

type Parent @entity {
  id: Bytes!
 child: Child!
}

type Child @entity {
  id: Bytes!
}

the result for a query like

query { parents(orderBy: child__id) } { id } }

is nondeterministic if multiple parents point to the same child. To make this entirely clear, assume there is only one instance of Child. The SQL query that gets generated is roughly

select * 
  from parent p 
    left join child c on (c.id = p.child) 
where ...
order by c.id

But when multiple rows in p have the same p.child, that ordering is ill-defined. We'd need to change that to order by c.id, p.id to make that deterministic.

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

No file or test is named in the issue. Reproduce the GraphQL query with multiple parents pointing to one child, inspect the generated SQL ordering, and trace the query-generation entry point responsible for child__id ordering. Done means equivalent results are deterministic when joined child values tie, while preserving the requested ordering.

Written by the indexing model from the issue text.

Assessment

Tech stack
graphql, rust, sql
Domain
backend-api-design, databases
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
42/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.