title: Android Room compile-time warning about column in foreign key not part of an index. What does it mean?
body: <p>I'm using Android's Room Persistence Library from the Android Architecture Components recently announced at Google I/O. Things seem to be working, but I'm getting the following error:</p>
  
  <blockquote>
    <p>Warning:tagId 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.</p>
  </blockquote>
  
  <p>My database has 3 tables: <code>Note</code>, <code>Tag</code>, and <code>JoinNotesTags</code>. Notes to Tags is a many-to-many relationship, hence the JoinNotesTags table to handle the mapping. The tables are straightforward:</p>
  
  <ul>
  <li><code>Note.id</code> and <code>Tag.id</code> are both primary keys</li>
  <li><code>JoinNotesTags.noteId</code> references <code>Note.id</code></li>
  <li><code>JoinNotesTags.tagId</code> references <code>Tag.id</code></li>
  </ul>
  
  <p>The foreign key constraints are defined on the <code>JoinNotesTags</code> table. For reference, here is the <code>CREATE TABLE</code> statement for the <code>JoinNotesTags</code> table:</p>
  
  <pre><code>"CREATE TABLE IF NOT EXISTS `JoinNotesTags` (
      `id` INTEGER PRIMARY KEY AUTOINCREMENT, 
      `noteId` INTEGER, 
      `tagId` INTEGER, 
      FOREIGN KEY(`noteId`) REFERENCES `Note`(`id`) ON UPDATE NO ACTION ON DELETE CASCADE , 
      FOREIGN KEY(`tagId`) REFERENCES `Tag`(`id`) ON UPDATE NO ACTION ON DELETE NO ACTION 
  )"
  </code></pre>
  
  <p>And here is the corresponding <code>@Entity</code> annotation for that class:</p>
  
  <pre><code>@Entity(
          indices = arrayOf(Index(value = *arrayOf("noteId", "tagId"), unique = true)),
          foreignKeys = arrayOf(
                  ForeignKey(
                          entity = Note::class,
                          parentColumns = arrayOf("id"),
                          childColumns = arrayOf("noteId"),
                          onDelete = ForeignKey.CASCADE),
                  ForeignKey(
                          entity = Tag::class,
                          parentColumns = arrayOf("id"),
                          childColumns = arrayOf("tagId"))
          )
  )
  </code></pre>
  
  <p>As you can see from the <code>@Entity</code> annotation, <code>tagId</code> <em>is</em> included in a composite unique index along with <code>noteId</code>. I've confirmed that this index is correctly defined in the auto-generated json schema file as well:</p>
  
  <pre><code>"CREATE UNIQUE INDEX `index_JoinNotesTags_noteId_tagId` 
      ON `JoinNotesTags` (`noteId`, `tagId`)"
  </code></pre>
  
  <p>So, my question: Is this warning just a bug in the (still-alpha-release) Room Library -- i.e. the compile-time analysis is missing the fact that <code>tagId</code> is part of this composite index? Or do I really have an indexing problem that I need to resolve in order to avoid full table scans?</p>