In order to process the results for long running queries or queries with relatively large result sets use the asynchronous execution mode. Additionally, to speed up the query you can try using an `INNER JOIN` statement instead. See details below:
1. Adjusting the query to a join instead of a sub query should speed up the execution:
SELECT *
FROM mydb://stable_lcs as slcs
INNER JOIN mydb://temp as tmp on tmp.objectid = slcs.objectid
2. Using the asynchronous option for query execution will allow the large result set to be dealt with separately. Note the `async_=True` below.
qid = queryClient.query(sql="""
SELECT *
FROM mydb://stable_lcs as slcs
INNER JOIN mydb://temp as tmp on tmp.objectid = slcs.objectid
""", async_=True)
This returns a job ID for the query that can be used to retrieve the results when the query is finished.
query.results(qid)
Here is a full Python example (without the login steps) that executes in async mode and waits for the query execution to finish:
import time
from dl import queryClient as query
# execute the query in async mode
qid = query.query(sql="""
SELECT *
FROM mydb://stable_lcs as slcs
INNER JOIN mydb://temp as tmp on tmp.objectid = slcs.objectid
""", async_=True)
# Loop and wait for the query to finish. We cannot access query results
# until the query is done.
while (status := query.status(qid)) != 'COMPLETED':
print("\r", f"Status: {status.ljust(9, ' ')};", end="")
if status == 'ERROR':
raise RuntimeError("Query execution failed")
time.sleep(5)
# when the query is completed the results can be accessed directly
query_results = query.results(qid)
print(query_results[:100])
Let us know if any of these steps resolve the issue for you. We also have many example notebooks that might help you while using the Data Lab client.
Thanks!