modernice / goes

goes is an event-sourcing framework for Go.
https://goes.modernice.dev
Apache License 2.0
134 stars 12 forks source link

Query Optimizer #37

Open bounoable opened 2 years ago

bounoable commented 2 years ago

An idea that came to my mind:

package example

func example(q1, q2 event.Query) {
  if query.IsSupersetOf(q2, q1) {
    log.Println("first query would return all events that the second query would return, and possibly more")
  }
}

If this could be implemented, projection jobs could further optimize queries for each individual projection. When a job applies itself onto multiple projections, it can check if a query that ran previously is a superset of the current query, and if so, just return the cached result from the previous query.

A query q1 is a superset of another query q2 if each of q1's filters/constraints is either less or equally restricting than q2's.