The generated SQL is available via the request
property:
echo $the_query->request;
where $the_query
is a \WP_Query
instance.
Check out how it’s formed in the class here.
Also available via the posts_request
filter for unsuppressed filtering.