Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

reactions index left out on purpose? #5507

Closed
r10s opened this issue Apr 28, 2024 · 1 comment · Fixed by #5643
Closed

reactions index left out on purpose? #5507

r10s opened this issue Apr 28, 2024 · 1 comment · Fixed by #5643
Assignees

Comments

@r10s
Copy link
Member

r10s commented Apr 28, 2024

during working on showing reactions in summaries i noticed that there is no sql-index over any reactions column - where we were adding index otherwise on even smaller tables - and reactions table can become quite big, it is only currently small as it is a new feature :)

also, the reaction table is queried often - at least for every message and every chatlist item displayed.

reactions use the following statements that need a full scan currently:

SELECT contact_id, reaction FROM reactions WHERE msg_id=?
SELECT reaction             FROM reactions WHERE msg_id=? AND contact_id=?
SELECT reaction             FROM reactions WHERE msg_id=? AND contact_id=?
DELETE                      FROM reactions WHERE msg_id=? AND contact_id=?

all of them could benefit from an index over msg_id - combined index is probably over the top as the most often called query is the first one.

wondering if the index was left out on purpose? cc @iequidoo @link2xt - otherwise, we should add one with CREATE INDEX reactions_index1 ON reactions(msg_id)

EDIT: or does the FOREIGN KEY(msg_id) imply an index? my source of truth is the sqlite3browser, maybe i've also overseen sth

@iequidoo
Copy link
Collaborator

I don't see in the SQLite docs that FOREIGN KEY implies an index. So, an index over msg_id is indeed worth being created

@iequidoo iequidoo self-assigned this May 31, 2024
iequidoo added a commit that referenced this issue May 31, 2024
This should speed up get_msg_reactions() filtering reactions by `msg_id`, but also other queries in
other places involving both `msg_id` and `contact_id`.
iequidoo added a commit that referenced this issue May 31, 2024
This should speed up `get_msg_reactions()` filtering reactions by `msg_id`, but also queries in
other places involving both `msg_id` and `contact_id`.
iequidoo added a commit that referenced this issue Jun 1, 2024
This should speed up `get_msg_reactions()` filtering reactions by `msg_id`, but also queries in
other places involving both `msg_id` and `contact_id`.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants