clockworklabs / SpacetimeDB

Multiplayer at the speed of light
https://spacetimedb.com
Other
4.41k stars 110 forks source link

SQL: Optimizations #1915

Open joshua-spacetime opened 3 weeks ago

joshua-spacetime commented 3 weeks ago

We will implement the following rule-based optimizations:

  1. Filter pushdown In particular pushing filters below joins. In the logical plan, WHERE conditions follow joins and will need to be pushed below the join in order to perform index selection.

  2. Join selection In the logical plan, joins are n-ary and are initially translated as cross joins. We need to optimize them as index joins if possible.

  3. Table scan + filter -> index scan After pushing down filters, we need to generate applicable index scans.

  4. Project pull up For both sql and subscriptions, the logical plan may have intermediate projections, but these can either be removed entirely, as is the case for subscriptions, or pulled up to the root of the query plan, as is the case for sql, to avoid materializing product values.

bfops commented 22 hours ago

we think this is re-implementing optimizations we used to have in the old, less-modular query engine. Keeping as P1 since this is fixing a "regression".