Executing Queries with Databricks SQL · Topic 1 of 3
SQL Warehouses, Genie Code and Federated Queries
Databricks Data Analyst: what a SQL warehouse does, serverless vs pro vs classic, Genie Code slash commands, and joining Delta tables with federated data.
- 5 min
- Every Databricks SQL query, dashboard, Genie Agent and alert runs on a SQL warehouse.
- Size sets per query power; minimum and maximum clusters handle concurrency; auto stop saves cost.
- Serverless starts in seconds; pro and classic take minutes and run in your cloud account.
What it is
A SQL warehouse is the compute resource that runs SQL in Databricks SQL. Every query from the SQL editor, an AI/BI dashboard, a Genie Agent, an alert or an external BI tool runs on one.
Genie Code (formerly Databricks Assistant) is the AI helper inside notebooks and the SQL editor that writes, explains and fixes code. Lakehouse Federation lets the same warehouse query external databases through Unity Catalog, so one query can join a Delta table with a table that still lives in, for example, PostgreSQL.
How it works
What the warehouse does in query execution
When you run a query, the warehouse parses and plans it, Unity Catalog checks that you hold the needed privileges, and the warehouse's clusters read the data and compute the result with the Photon engine. Results go back to the editor, dashboard or tool.
You pay for the warehouse while it runs. Its size (from 2X-Small upward) sets the power for each query, and its scaling range (minimum and maximum clusters) adds clusters when many users query at once. Auto stop shuts an idle warehouse down so it stops costing money.
Warehouse types
| Serverless | Pro | Classic | |
|---|---|---|---|
| Where compute runs | Databricks managed | Your cloud account | Your cloud account |
| Startup | Seconds (typically 2 to 6) | Minutes (about 4) | Minutes (about 4) |
| Photon | Yes | Yes | Yes |
| Predictive IO | Yes | Yes | No |
| Intelligent workload management | Yes | No | No |
Serverless suits BI and ad hoc work because it starts fast and scales quickly. Pro fits where serverless is unavailable or custom networking is needed; classic gives entry level performance.
Genie Code in the SQL editor and notebooks
| Feature | What it does |
|---|---|
| Ctrl+I (Cmd+I on macOS) | Opens Genie Code inline in a cell or the editor to write or edit code |
/explain | Explains the selected code |
/fix | Proposes a fix for an error, shown as a diff |
/optimize | Suggests performance improvements for a SQL query |
/findTables, /findQueries | Finds relevant tables or queries using Unity Catalog metadata |
/doc, /prettify | Adds comments; formats SQL for readability |
| Diagnose error | Appears on a failed cell and runs /fix automatically |
| Quick Fix | Suggests single line fixes for basic errors |
Genie Code also gives AI autocomplete as you type. It uses Unity Catalog metadata such as table names, columns and comments, which is why well documented tables give better suggestions.
Federated queries
Lakehouse Federation exposes an external database as a foreign catalog. An admin creates a connection (host, credentials), then a foreign catalog on it; after that, its tables use normal three level names.
CREATE CONNECTION pg_crm TYPE postgresql
OPTIONS (host 'crm.example.com', port '5432',
user secret('crm', 'user'), password secret('crm', 'pwd'));
CREATE FOREIGN CATALOG crm USING CONNECTION pg_crm OPTIONS (database 'crm');
A cross system query is then an ordinary join:
SELECT o.order_id, o.amount, c.segment
FROM main.sales.orders AS o
JOIN crm.public.customers AS c ON o.customer_id = c.id
WHERE c.country = 'US';
| Point | Detail |
|---|---|
| Access | Read only; you cannot write to a foreign catalog |
| Pushdown | Filters and other work are pushed to the source database over JDBC |
| Warehouse | Must be pro or serverless |
| Privileges | CREATE CONNECTION for the connection; CREATE CATALOG on the metastore plus CREATE FOREIGN CATALOG on the connection |
| Governance | Users need USE CATALOG, USE SCHEMA and SELECT as for any table |
Federation suits ad hoc reporting and proofs of concept without copying data.
How the exam asks about this
- "A dashboard query must join lakehouse sales with customers in a PostgreSQL database, without copying data." Use Lakehouse Federation: a connection, a foreign catalog, then a join.
- "A query fails with a column not found error in the SQL editor." Use Genie Code,
/fixor Diagnose error, to propose a corrected query. - "Many analysts hit the dashboard at 9 a.m. and queries queue." Raise the warehouse's maximum clusters (scaling), not only its size.
What to remember for the exam
- Every Databricks SQL query, dashboard, Genie Agent and alert runs on a SQL warehouse.
- Size sets per query power; minimum and maximum clusters handle concurrency; auto stop saves cost.
- Serverless starts in seconds; pro and classic take minutes and run in your cloud account.
- Genie Code: Ctrl+I inline,
/explain,/fix,/optimize, Diagnose error and Quick Fix. - Federation needs a connection and a foreign catalog; it is read only and needs pro or serverless.
- Federated tables are governed by Unity Catalog grants like any other table.
Federation does not copy data. Every federated query reaches the source database, so a busy dashboard can load a production system; for frequent heavy queries, ingest the data instead.
Common mistakes
Fixing concurrency with a bigger size. A larger warehouse makes each query faster. Queuing from many users is solved by more clusters through the scaling range.
Trying to write through federation. Foreign catalogs are read only. Loading federated data into the lakehouse means a CREATE TABLE ... AS SELECT into a Unity Catalog table.
Expecting Genie Code to bypass permissions. It suggests code from metadata you can see. The query still runs with your own privileges.
Check yourself
What does a SQL warehouse do when a dashboard runs a query?
It is the compute that plans and runs the query with Photon after Unity Catalog checks permissions, then returns the result to the dashboard.
What is needed before you can join a Delta table with a table in an external PostgreSQL database?
A Unity Catalog connection to the database and a foreign catalog created on it; then you join the tables with normal three level names on a pro or serverless warehouse.
Which Genie Code feature runs automatically when you click the button on a failed cell?
Diagnose error, which runs the
/fixcommand and proposes a corrected version of the code.
Topic 1 of 3 in Executing Queries with Databricks SQL
Test yourself on Executing Queries with Databricks SQL
The full Databricks Data Analyst Associate question bank has 600 questions, with timed practice exams and an explanation for every answer.
This study guide is independent and is not affiliated with, endorsed by, or sponsored by Databricks. Vendor names, certification names and exam codes are trademarks of their respective owners and are used for identification only.