mit-pdos / noria

Fast web applications through dynamic, partially-stateful dataflow
Apache License 2.0
4.98k stars 242 forks source link

Automatically detect aggregation subsumption #99

Open jonhoo opened 5 years ago

jonhoo commented 5 years ago

For example, a COUNT operator can be re-used in a SUM. Take the following two queries:

SELECT story_id, COUNT(*) AS vcount FROM votes GROUP BY story_id;
SELECT story_id, SUM(ratings) AS score FROM
  SELECT story_id, rating FROM ratings
  UNION
  SELECT story_id, 1 FROM votes;

The second query can re-use the first like this:

SELECT story_id, SUM(ratings) AS score FROM
  SELECT story_id, rating FROM ratings
  UNION
  (SELECT story_id, COUNT(*) FROM votes GROUP BY story_id);

to avoid re-counting all of the votes.