defradb icon indicating copy to clipboard operation
defradb copied to clipboard

Aggregating relation with a secondary index panics

Open AndrewSisley opened this issue 7 months ago • 0 comments

Found by David, e.g.:

type Foo {
  name: String @index(unique: true)
  bar: [Bar] 
}

type Bar {
  points: Int
  foo: Foo @index
}

// create docs

query {
  Bar( groupBy: [ bar_id ], filter: { bar_id: { _eq: "bae-d53e923f-0aed-5f0b-b179-274c32fe66a1" } } ) {
    foo { _docID }
    _sum( _group: { field: points } )
  }
}

Result:

 panic: runtime error: index out of range [1] with length 1
 
 -> github.com/sourcenetwork/defradb/internal/db/fetcher.(*IndexFetcher).newIndexDataStoreKeyWithValues
 ->   github.com/sourcenetwork/defradb/internal/db/fetcher/indexer_iterators.go:530

    github.com/sourcenetwork/defradb/internal/db/fetcher.(*IndexFetcher).newPrefixIndexIterator
      github.com/sourcenetwork/defradb/internal/db/fetcher/indexer_iterators.go:457
    github.com/sourcenetwork/defradb/internal/db/fetcher.(*IndexFetcher).createIndexIterator
      github.com/sourcenetwork/defradb/internal/db/fetcher/indexer_iterators.go:561
    github.com/sourcenetwork/defradb/internal/db/fetcher.(*IndexFetcher).Init
...

Example above is a rough obfuscation of a partner query, @AndrewSisley or David can provide the original if required but please don't add it to the ticket.

AndrewSisley avatar Jul 11 '24 18:07 AndrewSisley