Skip to content

Commit

Permalink
Rewrite mysql PaginateBranchesFromHistoryTree query (#3509)
Browse files Browse the repository at this point in the history
  • Loading branch information
dnr committed Oct 18, 2022
1 parent b57b930 commit 9a427c2
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions common/persistence/sql/sqlplugin/mysql/events.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,11 +62,13 @@ const (

getHistoryTreeQuery = `SELECT branch_id, data, data_encoding FROM history_tree WHERE shard_id = ? AND tree_id = ? `

// conceptually this query is WHERE (shard_id, tree_id, branch_id) > (?, ?, ?)
// but mysql doesn't execute it efficiently unless it's spelled out like this
paginateBranchesQuery = `SELECT shard_id, tree_id, branch_id, data, data_encoding
FROM history_tree
WHERE (shard_id, tree_id, branch_id) > (?, ?, ?)
ORDER BY shard_id, tree_id, branch_id
LIMIT ?`
FROM history_tree
WHERE (shard_id = ? AND ((tree_id = ? AND branch_id > ?) OR tree_id > ?)) OR shard_id > ?
ORDER BY shard_id, tree_id, branch_id
LIMIT ?`

deleteHistoryTreeQuery = `DELETE FROM history_tree WHERE shard_id = ? AND tree_id = ? AND branch_id = ? `
)
Expand Down Expand Up @@ -210,6 +212,8 @@ func (mdb *db) PaginateBranchesFromHistoryTree(
page.ShardID,
page.TreeID,
page.BranchID,
page.TreeID,
page.ShardID,
page.Limit,
)
return rows, err
Expand Down

0 comments on commit 9a427c2

Please sign in to comment.