Fix messages_preview index

This commit is contained in:
Fedor Indutny 2022-01-07 11:51:41 -08:00 committed by GitHub
parent f49df88877
commit fa8ff2ae4c
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 68 additions and 7 deletions

View file

@ -1292,4 +1292,36 @@ describe('SQL migrations test', () => {
);
});
});
describe('updateToSchemaVersion49', () => {
it('creates usable index for messages preview', () => {
updateToVersion(49);
const details = db
.prepare(
`
EXPLAIN QUERY PLAN
SELECT json FROM messages
WHERE
conversationId = 'convo' AND
shouldAffectPreview IS 1 AND
isGroupLeaveEventFromOther IS 0 AND
(
expiresAt IS NULL
OR
expiresAt > 123
)
ORDER BY received_at DESC, sent_at DESC
LIMIT 1;
`
)
.all()
.map(({ detail }) => detail)
.join('\n');
assert.include(details, 'USING INDEX messages_preview');
assert.notInclude(details, 'TEMP B-TREE');
assert.notInclude(details, 'SCAN');
});
});
});