mirror of
https://github.com/Foundry376/Mailspring.git
synced 2024-11-11 10:12:00 +08:00
perf(db): Flip order of columns in join table indexes for much faster querying
This commit is contained in:
parent
2bd83f38ff
commit
183924bfe5
2 changed files with 3 additions and 3 deletions
|
@ -32,7 +32,7 @@ describe "DatabaseSetupQueryBuilder", ->
|
|||
'CREATE TABLE IF NOT EXISTS `TestModel` (id TEXT PRIMARY KEY,data BLOB,client_id TEXT,server_id TEXT)',
|
||||
'CREATE UNIQUE INDEX IF NOT EXISTS `TestModel_id` ON `TestModel` (`id`)',
|
||||
'CREATE TABLE IF NOT EXISTS `TestModel-Label` (id TEXT KEY, `value` TEXT)'
|
||||
'CREATE UNIQUE INDEX IF NOT EXISTS `TestModel_Label_id_val` ON `TestModel-Label` (`id`,`value`)',
|
||||
'CREATE UNIQUE INDEX IF NOT EXISTS `TestModel_Label_val_id` ON `TestModel-Label` (`value` ASC, `id` ASC)',
|
||||
]
|
||||
for query,i in queries
|
||||
expect(query).toBe(expected[i])
|
||||
|
|
|
@ -45,9 +45,9 @@ class DatabaseSetupQueryBuilder
|
|||
attr.queryable && attr instanceof AttributeCollection
|
||||
collectionAttributes.forEach (attribute) ->
|
||||
joinTable = tableNameForJoin(klass, attribute.itemClass)
|
||||
joinIndexName = "#{joinTable.replace('-', '_')}_id_val"
|
||||
joinIndexName = "#{joinTable.replace('-', '_')}_val_id"
|
||||
queries.push("CREATE TABLE IF NOT EXISTS `#{joinTable}` (id TEXT KEY, `value` TEXT)")
|
||||
queries.push("CREATE UNIQUE INDEX IF NOT EXISTS `#{joinIndexName}` ON `#{joinTable}` (`id`,`value`)")
|
||||
queries.push("CREATE UNIQUE INDEX IF NOT EXISTS `#{joinIndexName}` ON `#{joinTable}` (`value` ASC, `id` ASC)")
|
||||
|
||||
joinedDataAttributes = _.filter attributes, (attr) ->
|
||||
attr instanceof AttributeJoinedData
|
||||
|
|
Loading…
Reference in a new issue