简体   繁体   English

这可能会导致在解析关系时进行全表扫描,强烈建议创建覆盖该列的索引

[英]This might cause a full table scan when resolving the relationship, it is highly advised to create an index that covers this column

I have many-to-many relationship between User and Poll.我在 User 和 Poll 之间存在多对多关系。 While creating the relating class below I'm getting this warning on compile time:在下面创建相关的 class 时,我在编译时收到此警告:

warning: The column pollId in the junction entity com.example.appproject.model.user.UserPollCrossRef is being used to resolve a relationship but it is not covered by any index.警告:联结实体 com.example.appproject.model.user.UserPollCrossRef 中的列 pollId 正用于解析关系,但它未被任何索引覆盖。 This might cause a full table scan when resolving the relationship, it is highly advised to create an index that covers this column.这可能会导致在解析关系时进行全表扫描,强烈建议创建一个覆盖该列的索引。

@Entity(primaryKeys = {"uid","pollId"})
public class UserPollCrossRef {
    @NonNull
    public String uid;
    @NonNull
    public String pollId;

    public UserPollCrossRef(@NonNull String uid, @NonNull String pollId) {
        this.uid = uid;
        this.pollId = pollId;
    }
}

I wanted to ask what does it mean and how can I fix it?我想问一下这是什么意思,我该如何解决?

It looks as though the UserPollCrossRef is an associate/reference/mapping (and other names) table for a many-many relationship between user and poll.看起来 UserPollCrossRef 是一个关联/引用/映射(和其他名称)表,用于用户和轮询之间的多对多关系。

what does it mean这是什么意思

The primary key is according to uid and pollid combined in that order, thus finding the uid is fast as the uid is the first part of the primary key.主键是按照uid和pollid的顺序组合的,所以uid是主键的第一部分,所以查找uid的速度很快。

However when/if searching for the pollid then there is no index ordered according to the pollid and hence the suggestion that such an index is created.但是,当/如果搜索 pollid 时,则没有根据 pollid 排序的索引,因此建议创建这样的索引。

you may wish to consider looking at https://www.essentialsql.com/what-is-a-database-index/您不妨考虑查看https://www.essentialsql.com/what-is-a-database-index/

Room is simple saying that in some circumstances and index may be beneficial, it is just a warning.房间很简单,说在某些情况下索引可能是有益的,它只是一个警告。

how can I fix it?我该如何解决?

The simplest way is to use @ColumnInfo(index = true) eg最简单的方法是使用@ColumnInfo(index = true)例如

@Entity(primaryKeys = {"uid","pollId"})
public class UserPollCrossRef {
    @NonNull
    public String uid;
    @NonNull
    @ColumnInfo(index = true)
    public String pollId;

    public UserPollCrossRef(@NonNull String uid, @NonNull String pollId) {
        this.uid = uid;
        this.pollId = pollId;
    }
}

The alternative would be to utilise the indices parameter of the @Entity annotation eg另一种方法是利用@Entity注释的 indices 参数,例如

@Entity(primaryKeys = {"uid","pollId"},
        indices = {
        @Index(value = "pollId")
        }
)
public class UserPollCrossRef {
   @NonNull
   public String uid;
   @NonNull
   public String pollId;

   public UserPollCrossRef(@NonNull String uid, @NonNull String pollId) {
      this.uid = uid;
      this.pollId = pollId;
   }
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 在sqlite中使用全文搜索时如何索引一列? - How to index one column when use full text search in sqlite? 运行Camera.release()时,可能导致NullPointerException的原因是什么? - What might cause a NullPointerException when running Camera.release()? 当android有互联网连接时如何建议 - How to be advised when android has internet connection 什么时候在requestLocationUpdates上建议PendingIntent和LocationListener? - When is advised PendingIntent vs. LocationListener on requestLocationUpdates? JSON中此错误的可能原因是什么? - What might be the cause of this error in JSON? 什么可能导致 android 出现此错误? - What might cause this error in android? 无法从动态创建的sqlite表的列中检索单个字符串数据,并导致“请求索引0,大小为0” - Unable to retrieve a single string-data from sqlite table'column which is dynamically created and cause “Index 0 requested, with a size of 0” 带索引的房间创建表 - Room Create Table with Index BottomSheetDialog 覆盖整页 - Android SDK - BottomSheetDialog covers full page - Android SDK lazy column list item 较长时,键盘覆盖 Jetpack Compose 中的 Textfield - When the lazy column list item is long, the Keyboard covers the Textfield in Jetpack Compose
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM