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

DB: some missing indices #890

Merged
merged 9 commits into from
Jul 20, 2024
Merged

DB: some missing indices #890

merged 9 commits into from
Jul 20, 2024

Conversation

ArnyminerZ
Copy link
Member

@ArnyminerZ ArnyminerZ commented Jul 5, 2024

Purpose

Add missing indices to database

Short description

  • Indexed Collection#ownerId.
  • Indexed WebDavDocument#parentId
  • Increased database version number

Checklist

  • The PR has a proper title, description and label.
  • I have self-reviewed the PR.
  • I have added documentation to complex functions and functions that can be used by other modules.
  • I have added reasonable tests or consciously decided to not add tests.

@ArnyminerZ ArnyminerZ added the refactoring Internal improvement of existing functions label Jul 5, 2024
@ArnyminerZ ArnyminerZ self-assigned this Jul 5, 2024
@ArnyminerZ ArnyminerZ linked an issue Jul 5, 2024 that may be closed by this pull request
@ArnyminerZ ArnyminerZ requested a review from rfc2822 July 5, 2024 09:51
@ArnyminerZ ArnyminerZ marked this pull request as ready for review July 5, 2024 09:51
@rfc2822 rfc2822 requested review from sunkup and removed request for rfc2822 July 5, 2024 10:54
@rfc2822
Copy link
Member

rfc2822 commented Jul 8, 2024

The Collection pushTopic should also be an index, because we will search for a collection with a specific topic when we receive a push message. The index should probably be non-unique, although it's intended to be unique – but if it's not for some reason, it shouldn't interfere with other functionality (and prevent having multiple collections with different URLs and same push topic, for instance).

Copy link
Member

@sunkup sunkup left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What @rfc2822 said :)

@ArnyminerZ ArnyminerZ requested a review from sunkup July 9, 2024 10:25
Copy link
Member

@rfc2822 rfc2822 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hm, compilation of the tests still shows this message (in the assembleDebug step):

w: [ksp] /home/runner/work/davx5-ose/davx5-ose/app/src/main/kotlin/at/bitfire/davdroid/db/WebDavDocument.kt:33: parentId column references a foreign key but it is not part of an index. This may trigger full table scans whenever parent table is modified so you are highly advised to create an index that covers this column.

@ArnyminerZ Do you have an idea where this could come from?

@rfc2822 rfc2822 force-pushed the 873-db-some-missing-indices branch from 56854d9 to 762e1c8 Compare July 15, 2024 08:02
@rfc2822
Copy link
Member

rfc2822 commented Jul 15, 2024

After a rebase, the message is still there:

w: [ksp] /home/runner/work/davx5-ose/davx5-ose/app/src/main/kotlin/at/bitfire/davdroid/db/WebDavDocument.kt:33: parentId column references a foreign key but it is not part of an index. This may trigger full table scans whenever parent table is modified so you are highly advised to create an index that covers this column.

@ArnyminerZ
Copy link
Member Author

I've tried everything that came up to my mind, and this is the only thing that works. I don't know if it's a bug, or if it's supposed to be this way, but the warning should be gone.

@ArnyminerZ
Copy link
Member Author

Working on the failing tests

@ArnyminerZ ArnyminerZ requested a review from rfc2822 July 15, 2024 11:19
Index("mountId", "parentId", "name", unique = true)
Index("mountId"),
Index("parentId"),
Index("name", unique = true),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this would forbid the same file name ("README") to be present in different directories/mounts. We should keep the original index, if possible.

Above two foreign keys with childColumn=mountId and childColumn=parentId are defined. ForeignKey docs say:

It is also recommended to create an index on the child table to avoid full table scans when the parent table is modified. If a suitable index on the child table is missing, Room will print RoomWarnings. MISSING_INDEX_ON_FOREIGN_KEY_CHILD warning.

So we need two indices:

  • mountId (will be used to find the children when a WebDavMount is deleted) – this is already covered by the Index("mountId", "parentId", "name", unique = true) index because it's the leftmost column, and
  • parentId (will be used to find the children when a WebDavDocument is deleted).

It should be enough to just add a normal index about parentId.

@ArnyminerZ ArnyminerZ requested a review from rfc2822 July 20, 2024 09:12
Signed-off-by: Arnau Mora <arnyminerz@proton.me>
Signed-off-by: Arnau Mora <arnyminerz@proton.me>
Signed-off-by: Arnau Mora <arnyminerz@proton.me>
Signed-off-by: Arnau Mora <arnyminerz@proton.me>
Signed-off-by: Arnau Mora Gras <arnyminerz@proton.me>
Signed-off-by: Arnau Mora <arnyminerz@proton.me>
Signed-off-by: Arnau Mora <arnyminerz@proton.me>
Signed-off-by: Arnau Mora <arnyminerz@proton.me>
Signed-off-by: Arnau Mora Gras <arnyminerz@proton.me>
@rfc2822 rfc2822 force-pushed the 873-db-some-missing-indices branch from 173c02b to 52f98ad Compare July 20, 2024 15:31
@rfc2822
Copy link
Member

rfc2822 commented Jul 20, 2024

Looks good, works and all warnings gone :)

@rfc2822 rfc2822 merged commit fafa358 into main-ose Jul 20, 2024
8 checks passed
@rfc2822 rfc2822 deleted the 873-db-some-missing-indices branch July 20, 2024 15:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
refactoring Internal improvement of existing functions
Projects
None yet
Development

Successfully merging this pull request may close these issues.

DB: some missing indices
3 participants