MySQL - Optimal indexing for a lookup table. HASH index, BTREE index or composite PK?
a: Satisfy the WHERE with INDEX(something, time)
MyLookup -- If the pair (FKToTableA, FKToTableB) is unique, then make that the PRIMARY KEY, and put the columns in that order so that your SELECT can quickly get into MyLookup.
Don't use BIGINT (8 bytes) unless you expect to exceed 4 billion, the limit for INT UNSIGNED, which takes only 4 bytes.
IP addresses -- for the old IPv4, there are convenient routines for converting to INT UNSIGNED.  For the new IPv6, it won't fit into BIGINT.  See 5.6.3.
Do those Metadata columns need utf8?  Can they be combined into a TEXT column?  And other questions.
Build and maintain a "Summary table" rather than scanning large chunks of the "Fact" table to get this "report".
Do the SUMs before JOINing to b.
Do you really need a many-to-many mapping table?  Seems like this is 1:many.
More tips on many-to-many.