I'm using Spark SQL to create a DataFrame via JDBC connection. But Spark often use subquery to get data from database, which cause MySQL create too many (too large) derived tables. I'm trying to solve this problem, could I construct the DataFrame by myself, such as define a function that return a set of data and let Spark send this function to workers for execute ? Or do I have any other way to avoid Spark using subquery ?