Indexes: There are two indexes defined on this bucket related to the query that isn’t performing well.
CREATE PRIMARY INDEX `#primary` ON `graph` USING GSI
CREATE INDEX `idx_audience` ON `graph`(`head.id`) WHERE ((`type` = "arc") and (`relation.follow` = true)) USING GSI
Issue: The query
SELECT s.tail.id FROM graph s WHERE s.type='arc' AND s.relation.follow=true AND s.head.id='999'
doesn’t use the secondary index (idx_audience). Instead it uses the primary index (as per the query plan generated using EXPLAIN). This causes the query performance to deteriorate linearly.
Adding a USE INDEX hint also doesn’t seem to help. (Query plan generated using EXPLAIN for the query below still shows that the primary index is being used).
SELECT s.tail.id FROM graph s USE INDEX (idx_audience USING GSI) WHERE s.type='arc' AND s.relation.follow=true AND s.head.id='999’
Hi @lakshsubra, the suggestion from @isha works with later versions. You can upgrade to 4.5.1 or later, or add head_id = 999 to your index WHERE clause.