android_catalogue1-3 Exercise 2: Items per Tag =============================================== In ItemTagDao: @Query("SELECT COUNT(*) FROM item_tag WHERE tagId = :tagId") fun observeCountForTag(tagId: Long): Flow In CatalogueRepository: fun itemCountForTag(tagId: Long): Flow = itemTagDao.observeCountForTag(tagId) The index that makes it quick is Index(value = ["tagId"]) on the item_tag entity (Chapter 2). The composite primary key (itemId, tagId) starts with itemId, so it cannot serve a lookup by tagId alone. Because the method returns a Flow, a screen showing the count updates by itself when an item gains or loses the tag.