Which Table Will Get Locked With This Query
The way I interpret Transactions and Concurrency on the TokuDB wiki


  Insert select
  
  
  Serializable
  Grab read locks on all key ranges read by query
  Grab write locks on all keys written
  Repeatable read
  Grab read locks on all key ranges read by query
  Grab write locks on all keys written
  Read committed
  Grab write locks on all keys written
  Read uncommitted
  Grab write locks on all keys written
  


Inserts by the 3rd party application would need to update the keys and they may happen to be locked for certain rows that at the same time are selected-to-be-inserted by that query.

The way I solved it in my case which is make the query run for time slices slightly in the past so it cannot coincide with that application (which actually adds the data).