Sub topic 1
What a SQL warehouse is and when to use one
Prerequisites
This chapter assumes you can:
- Write basic SQL:
SELECT,WHERE,JOIN, andGROUP BY. - Find your way around the Databricks workspace sidebar.
- Describe what tables, schemas, and catalogs are.
- Explain in general terms how cloud compute is billed, by time running and by size.
You do not need to have created a warehouse before.
What a SQL warehouse is
A SQL warehouse is a compute resource in Databricks that runs SQL statements. When you run a query in the SQL editor, the warehouse reads the data, does the work, and returns the result. The editor itself only holds your text. The warehouse supplies the CPU, memory, and caching.
Despite the name, a SQL warehouse is not a data warehouse in the storage sense. It stores no data. Your tables live in cloud object storage and are governed by Unity Catalog. The warehouse is the engine you point at them. You can stop it, resize it, or replace it, and the tables stay where they are.
Under the hood, a warehouse is one or more clusters of machines. A cluster is a group of machines that work together on one query. The warehouse runs the Photon engine, a Databricks query engine written in C++ that is built for SQL. Details such as cluster size and scaling are covered in later chapters. For now, treat a warehouse as a named, configurable engine that you start, stop, and share.
How it differs from other Databricks compute
Databricks has several kinds of compute. The two you will meet first are SQL warehouses and all-purpose or jobs compute (clusters). They overlap in what they can do, but they are tuned for different work.
| Aspect | SQL warehouse | All-purpose or jobs cluster |
|---|---|---|
| Main language | SQL | Python, Scala, R, and SQL |
| Typical use | Queries, BI tools, dashboards, alerts | Notebooks, data engineering, machine learning |
| Configuration | Few settings: type, size, scaling, auto stop | Many settings: runtime version, node types, libraries, Spark configuration |
| Concurrency | Built to serve many users running queries at once | Shared by users, but tuned mostly for heavy batch or interactive code |
| Entry points | SQL editor, dashboards, BI connectors, SQL APIs | Notebooks, jobs, libraries |
The practical difference is how much you manage. With a cluster you choose a Databricks Runtime version, install libraries, and tune Spark settings. With a warehouse, Databricks manages the runtime and you choose only a handful of options. That makes warehouses easier to operate, and it limits what you can run. You cannot execute arbitrary Python on a warehouse.
When to use a SQL warehouse
Use a warehouse when the work is SQL and the people or tools asking for results want quick answers.
Good fits:
- Ad hoc analysis in the SQL editor.
- Dashboards that many people open during the day.
- Alerts that run a query on a schedule and notify someone.
- BI tools such as Tableau or Power BI that connect through JDBC or ODBC.
- Programmatic SQL from applications, through drivers or the Statement Execution API.
- SQL tasks inside Databricks Jobs, such as a scheduled
INSERTorMERGE.
Poor fits:
- Python or Scala data processing, including machine learning training. Use a cluster.
- Work that needs custom libraries or a specific runtime version.
- Streaming code written in Python or Scala.
Many teams use both. An engineering team runs pipelines on jobs compute and writes curated tables. Analysts then query those tables from a warehouse.
The life of a query
It helps to know what happens between pressing Run and seeing rows. The sequence below matters for later chapters on auto stop and cost.
Three points follow from this flow:
- The warehouse must be running. If it is stopped, it starts when you submit a query, or you start it yourself. Starting takes time on pro and classic warehouses and is usually much faster on serverless. A later chapter compares the types.
- Permissions are checked twice. You need permission to use the warehouse. Unity Catalog separately checks that you may read the tables the query touches. Having one without the other gives an error.
- Data stays in storage. The warehouse reads from there on each query, and may serve repeated work from its caches.
Creating and inspecting a warehouse
You usually create a warehouse in the workspace: open SQL Warehouses in the sidebar, then choose Create SQL warehouse. You set a name, a cluster size, and a few scaling options. Many workspaces already have a starter warehouse, so check the list before you create another.
To confirm what a warehouse can see, attach it in the SQL editor and run:
SHOW CATALOGS;
SELECT * FROM samples.nyctaxi.trips LIMIT 10;SHOW CATALOGS lists the catalogs you are allowed to see. The second statement reads a sample table using its full catalog.schema.table name. The samples catalog is available in most workspaces and is handy for practice. If it is missing, ask your admin or substitute a table you can read.
Common errors and gotchas
- "No warehouse selected" or a greyed-out Run button. The editor needs a warehouse attached. Choose one from the compute selector at the top of the editor.
- Permission denied on the warehouse. You need at least the Can use permission on the warehouse. This is separate from table permissions.
- Permission denied on a table. The warehouse is fine, but Unity Catalog denies you
SELECTon a table orUSEon its catalog or schema. Ask the data owner, not the warehouse admin. - A slow first query. A stopped warehouse has to start before it can run anything. Later queries are faster. This is a startup delay, not a slow query.
- Surprise cost. A running warehouse is billed while it runs, even when no one is querying. Auto stop, covered in a later chapter, limits this.
- Expecting Python to work. A SQL warehouse accepts SQL only. If you need Python, switch to a cluster.
What to carry forward
A SQL warehouse is managed, SQL-only compute that is separate from your data. You attach one in the editor, it must be running to execute a statement, and two sets of permissions apply: one for the warehouse and one for the data. The next chapters cover the warehouse type, size, and scaling choices that decide speed and cost.
Exercise
A colleague says their query returned "permission denied" even though they can start and use the shared warehouse. Name the likely cause and who can fix it. Then say whether a SQL warehouse would be the right compute for a nightly Python feature-engineering job, and why.
Show answer
The warehouse permission is fine. The likely cause is missing Unity Catalog privileges on the data, such as SELECT on the table or USE CATALOG and USE SCHEMA on its parents. The data owner or someone with grant rights on that object can fix it, not the warehouse admin. A SQL warehouse is not the right choice for a Python job, because warehouses run SQL only. Use a jobs cluster or serverless jobs compute instead.
Exercise
Why does the first query of the morning sometimes take much longer than the same query run a minute later?
Show answer
If the warehouse was stopped by auto stop overnight, it has to start before it can run the query. That startup time is added to the first query. The second query finds the warehouse already running, so it is not delayed.