# Control spend and long-running hybrid queries Source: https://www.hotdata.dev/use-cases/query-spend Site index: https://www.hotdata.dev/llms.txt Some queries finish in milliseconds; others chew through huge tables. Async execution, saved results, background refreshes, and a single place to watch jobs mean you're not guessing what's still running or re-paying for the same read twice. ## How it works ### Step 1: Prefer async when integrations might lag **Claude** ``` How many events did we get today in the huge events table? If the answer isn’t ready yet, show me how to check when the count is done. ``` **CLI** ```bash hotdata query "SELECT COUNT(*) FROM huge.public.events WHERE dt = CURRENT_DATE" # If the CLI prints query_run_id → poll: hotdata query status qr_abc123 ``` **Python SDK** ```python import hotdata query_api = hotdata.QueryApi(api_client) runs = hotdata.QueryRunsApi(api_client) submitted = query_api.query( hotdata.QueryRequest( sql="SELECT COUNT(*) FROM huge.public.events WHERE dt = CURRENT_DATE", var_async=True, ), ) runs.get_query_run(submitted.query_run_id) ``` When waiting synchronously isn't worth it, the CLI hands back a **`query_run_id`**. Poll status instead of blocking on the terminal. ### Step 2: Reuse stored results instead of re-running **Claude** ``` Show my last 5 query runs, then let me read the stored rows from one of them without re-running the same SQL. ``` **CLI** ```bash hotdata databases queries list --limit 5 hotdata databases results get rslt_xyz789 ``` **Python SDK** ```python import hotdata runs = hotdata.QueryRunsApi(api_client) runs.list_query_runs(limit=5) results = hotdata.ResultsApi(api_client) results.get_result("rslt_xyz789") ``` ### Step 3: Tune connection refresh, not blind rescans **Claude** ``` Our shared finance Snowflake is out of date. Refresh it so the table list here matches the warehouse again. ``` **Python SDK** ```python import hotdata refresh = hotdata.RefreshApi(api_client) refresh.refresh(hotdata.RefreshRequest(connection_id="snowflake")) ``` A schema refresh reconciles the catalog in the background. Give it a moment before you trust **`hotdata databases tables list`** for brand-new upstream DDL. ### Step 4: Watch jobs that balloon latency **Claude** ``` What’s running in the background right now? Then show me full detail for one of those runs. ``` **CLI** ```bash hotdata jobs list --status running hotdata jobs job_123 ``` **Python SDK** ```python import hotdata jobs = hotdata.JobsApi(api_client) jobs.list_jobs(status="running") jobs.get_job("job_123") ``` **`jobs list`** shows what's still running: long index builds, refreshes, whatever's in flight. **`jobs `** tells you when it's finished. ## Who uses this - Finance or ops tying spend and latency back to query-run metadata. - ML or eval pipelines firing lots of short reads against shared warehouses. Reuse results instead of repeating work. - Anyone who'd rather poll or reuse than block on long-running hybrid queries.