sapling/changesets
Thomas Orozco 14b0de09e2 mononoke/changesets: Make SelectChangeset >800x times faster on sqlite
Summary:
Our code to select changesets returns a result set that looks like this:

```
GEN|P1_ID
GEN|P2_ID
```

Where `GEN` is the generation of the commit being selected and `PX_ID` are the
IDs of its parents. If there are no parents, it'll look like:

```
GEN|NULL
```

However, this doesn't optimize very well on sqlite, and this query ends up
taking several seconds even on fairly modest datasets, as SQLite produces a
join table containing all changesets / csparents pairs before filtering them.

This diff updates our logic to instead use a union query instead in order to do
the selection in two blocks: first, we get the parents we care about out of the
csparents table (which is fast), and separately, we get the one changeset we
care about out of the changesets table.

This is perhaps also a little easier to interpret as it avoids the special case
on parents with no commits. Indeed, the dataset now always looks like:

```
GEN|NULL|NULL
GEN|P1_ID|P1_SEQ
GEN|P2_ID|P2_SEQ
```

On MySQL, this doesn't really seem to make a difference from a performance
perspective. I'm guessing MySQL optimizes this more appropriately.

Reviewed By: StanislavGlebik

Differential Revision: D18573813

fbshipit-source-id: 940954bf067c429b8419b9b0f9ee799c2d06e8f1
2019-11-20 07:12:40 -08:00
..
if Rename rust2 code generator to rust 2019-11-04 13:06:55 -08:00
schemas mononoke: remove mysql schemas 2019-02-08 03:04:01 -08:00
src mononoke/changesets: Make SelectChangeset >800x times faster on sqlite 2019-11-20 07:12:40 -08:00