Fixed timeout MySQL grounding query

The bug was because a query in inference run for too long.

Created an index on the id column of type table to optimize MySQL join,
since MySQL uses BNLJ. It's important to tailor join queries for MySQL
as they don't have efficient join algorithms. Specifically, we should
create indexes on join condition columns (at least in MySQL
implementation).