I often break my complicated queries into temporary tables so I can comment them and help me comprehend the steps.
Does this differ greatly from how mysql handle’s nested joins internally?
e.g. select * from t1,t2,t3,t4 where t1.id=t2.id and t2.id2 = t3.id2, t4.id3 = t3.id3
Does an index(s) defined on t1 get “carried over” to whatever internal table mysql creates to hold intermediate results?
Is there any major difference performance wise between explicitly defining temporary tables or using one single query full of nested joins?
Indexes are not carried over to temporary tables you explicitly create. They’re just like regular tables, except that they’ll disappear when you no longer have the session open. The database has no knowledge that the data in the table originally came from a query on some other tables that had indexes; for one thing you might have inserted/deleted/updated rows in the temp table since the query.
I would expect mysql to make use of any indexes it thought would be beneficial when you run joins, but the index has to be on a table in the join.