Android Room compile-time warning about column in foreign key not part of an index. What does it mean? Android Room compile-time warning about column in foreign key not part of an index. What does it mean? sqlite sqlite

Android Room compile-time warning about column in foreign key not part of an index. What does it mean?


When in kotlin code:

Before

@ColumnInfo(name = "question_id")var questionId: Long

After

@ColumnInfo(name = "question_id", index = true) //just add index = truevar questionId: Long


You need to add index to columns for faster queriesHere is an example

@Entity(indices = {@Index("artist_id")})public class Artist{    @NonNull    @PrimaryKey    @ColumnInfo(name = "artist_id")    public String id;    public String name;}


When you modify the Tag table, the database might need to lookup corresponding rows in the JoinNotesTags table. To be efficient, this requires an index on the tagId column.

Your composite index is not useful for that; because of the way how indexes work, the column(s) to be searched must be the leftmost column(s) in the index.

You should add an index on only the tagId column.(You could swap the order of the columns in the composite index, but then you'd have the same problem with noteId.)