Trino hands-on: federated SQL over data that lives somewhere else
Hands-on Trino guide: architecture, connectors, catalogs, federated queries, pushdown, joins, partitions, performance, and when not to use it.
Table of Contents
Monday morning, before the first meeting, someone asks how many premium customers bought something last month. The answer is split across three systems: customers live in PostgreSQL, orders in Iceberg on S3, and the product catalog in MySQL. The question arrives with a “can you send it as a spreadsheet?”
The usual reaction is to export three CSVs, open them in pandas, and pray that the dates and identifiers line up. It works once. The second time, someone renamed a column, the file is four GB, and the analysis turns into an afternoon of cleanup.
Trino exists for that moment. You point SQL at the original sources, join tables across systems, and get a result without moving the data into a warehouse. This guide walks through the tool from architecture to tuning, with code you can run in a local environment.
What Trino is and what it actually solves
Trino is a distributed SQL engine for querying data that lives in one or more heterogeneous systems. It does not store the data. It turns a query into a distributed plan, asks each connector for its slice, and combines the results in memory.
That makes it a query layer, not a database. It does not compete with PostgreSQL to serve transactional APIs or with a warehouse to govern the company’s semantic model. It competes with the habit of exporting everything to a CSV.
| Tool | Model | When to use it |
|---|---|---|
| PostgreSQL | OLTP, row by row | Transactions, applications, operational data |
| Warehouse | Managed OLAP | Concurrent BI, governed models, predictable cost |
| Spark | Distributed batch compute | Heavy transformations, pipelines, ML |
| Trino | Distributed SQL query | Interactive analytics and cross-source federation |
It shines when you need to join operational data with a lakehouse, audit a migration, explore an Iceberg catalog without spinning up Spark, or give an analyst a single door into five systems.
Coordinator, workers, and the execution model
A Trino cluster has one coordinator and one or more workers. The coordinator parses the statement, analyzes types, plans, optimizes, and schedules work. Workers execute tasks, read from connectors, and exchange intermediate data with each other.
flowchart LR
C[Client] --> CO[Coordinator]
CO --> W1[Worker 1]
CO --> W2[Worker 2]
W1 --> PG[(PostgreSQL)]
W1 --> ICE[(Iceberg / S3)]
W2 --> MY[(MySQL)]
A query splits into stages, stages into tasks, tasks into drivers, and each driver chains operators that consume splits. Intermediate stages communicate through exchanges.
SELECT *
FROM system.runtime.nodes;
That query lists the visible nodes, their state, and their version. If a worker is missing, the problem is discovery or networking, not SQL.
Connectors, catalogs, and schemas
A connector adapts Trino to a system: PostgreSQL, Iceberg, MySQL, Kafka, MongoDB. A catalog is a named configuration that instantiates that connector. The filename in etc/catalog/ becomes the catalog name: postgres.properties creates the postgres catalog.
Inside a catalog are schemas, and inside schemas are tables. The fully qualified name always has three parts: catalog.schema.table. That explicit root is what lets one query cross two systems without ambiguity.
SHOW CATALOGS;
SHOW SCHEMAS FROM postgres;
DESCRIBE postgres.public.customers;
The connector must declare connector.name; everything else depends on the system. A misconfigured catalog does not fail at startup: it fails on the first query.
The first federated query
Suppose PostgreSQL holds the accounts and an Iceberg catalog holds the orders. The minimum configuration for the relational catalog fits in one file.
# etc/catalog/postgres.properties
connector.name=postgresql
connection-url=jdbc:postgresql://postgres:5432/app
connection-user=trino
connection-password=secret
The second catalog points at an Iceberg REST Catalog and an S3-compatible store. I use MinIO here so the example is reproducible locally; in production the endpoint and credentials change, not the shape.
# etc/catalog/lake.properties
connector.name=iceberg
iceberg.catalog.type=rest
iceberg.rest-catalog.uri=http://iceberg-rest:8181
fs.native-s3.enabled=true
s3.region=us-east-1
s3.endpoint=http://minio:9000
s3.path-style-access=true
With both catalogs loaded, the query is plain SQL. Trino asks PostgreSQL only for the columns and rows it needs, reads the relevant Iceberg partitions, and joins both sides in memory.
SELECT
c.segment,
count(*) AS orders,
sum(o.total) AS revenue
FROM postgres.public.customers c
JOIN lake.sales.orders o
ON o.customer_id = c.id
WHERE o.order_date >= DATE '2026-11-01'
AND c.active = true
GROUP BY c.segment
ORDER BY revenue DESC;
No export, no staging table, no duplicated dataset. The cost is whatever data Trino cannot push down to the sources. That is where tuning begins.
Pushdown: the art of not fetching everything
Pushdown means delegating part of the work to the source. It covers predicates, column projection, dereference of nested fields, aggregations, joins, LIMIT, and Top-N. If the connector supports it, Trino sends the filter to PostgreSQL or the partition pruning to Iceberg instead of fetching everything and filtering in memory.
EXPLAIN
SELECT o.order_id, o.total
FROM lake.sales.orders o
WHERE o.order_date = DATE '2026-12-04'
AND o.total > 100;
In the plan, a TableScan with constraint on ... means the filter traveled to the source. If a ScanFilterProject sits above it, Trino is filtering after reading. The difference between those plans can be one day of partitions or three years.
Aggregation pushdown is conditional. ROLLUP, CUBE, GROUPING SETS, coercions, expressions inside the function, and aggregates with ORDER BY or FILTER usually stay in Trino. Join pushdown requires both tables in the same catalog and every predicate to be pushable.
Joins: distribution, statistics, and order
Trino chooses between a broadcast join, which replicates the right side to every node, and a partitioned join, which hashes both sides by the join key. join_distribution_type defaults to AUTOMATIC: with statistics, the optimizer decides; without them, it leans toward partitioned.
Statistics drive the decision. A recent ANALYZE lets Trino estimate cardinality and pick the correct build side. Without statistics, the optimizer guesses, and a guess across a billion rows is expensive.
ANALYZE lake.sales.orders;
SHOW STATS FOR lake.sales.orders;
SET SESSION join_distribution_type = 'PARTITIONED';
Broadcast is fast when the dimension is genuinely small; if it does not fit in per-node memory, the join fails or spills. Partitioned moves more data but scales to tables that no single worker can hold.
Dynamic filtering is enabled by default and is one of the highest-leverage optimizations: Trino collects keys from the small side and pushes them into the large side’s scan so it never reads rows the join will discard. In Iceberg and Hive it becomes partition and row-group pruning. Check the plan for dynamicFilterAssignments on the join and dynamicFilters on the scan.
Partitions and pruning: reading fewer files
In a lakehouse, partitioning is the first line of defense. Filtering by order_date on a table partitioned by order_date discards files before opening them. Wrapping the column in date_format breaks pruning and turns one day into a full scan.
SELECT count(*) AS orders
FROM lake.sales.orders
WHERE order_date >= DATE '2026-12-01'
AND order_date < DATE '2026-12-02';
That semantic range works even when the table uses hidden partitioning by month, day, or bucket. Iceberg keeps the transform in metadata, so the filter applies to the partition without you knowing its physical layout.
After partition pruning comes file pruning: min/max per column, null counts, and, in some formats, bloom filters. Small files degrade both. A hundred thousand 1 MB files take longer to plan than to read, and the fix is compaction, not more workers.
Performance: memory, concurrency, and spill
Trino is an in-memory engine. A join builds a hash table, an aggregation keeps state, and an ORDER BY accumulates rows. When that memory exceeds the limits, the query is killed instead of degrading silently.
The defaults tell the story: query.max-memory is 20 GB per query across the cluster, and query.max-memory-per-node is 30% of the node’s heap. A worker with 16 GB of heap has an effective user-memory ceiling much lower than the number suggests.
SELECT query_id, state, query
FROM system.runtime.queries
WHERE state = 'RUNNING';
That lists what is running. To stop a query that is sinking the cluster, use the system connector procedure with the identifier and a message for the user.
CALL system.runtime.kill_query(
query_id => '20261205_101500_00001_abcde',
message => 'Exceeds the analytics team memory budget'
);
Spill to disk exists, but current documentation marks it as legacy and recommends fault-tolerant execution with a TASK retry policy and a configured exchange manager. Do not design the cluster assuming disk will save a badly sized join.
Resource groups govern concurrency with memory, CPU, and query limits per group. Without separation, an accidental SELECT * competes with the dashboard the executives are watching.
Cluster vs local: setting up a real environment
For development, one process can act as both coordinator and worker. The configuration is explicit: the node accepts queries and also runs tasks.
# etc/config.properties (single development node)
coordinator=true
node-scheduler.include-coordinator=true
http-server.http.port=8080
discovery.uri=http://localhost:8080
In a real cluster, the coordinator does not execute tasks and workers point at its discovery URI. You also need a shared secret for internal communication, TLS, and authentication once it leaves your network.
# etc/config.properties (worker)
coordinator=false
http-server.http.port=8080
discovery.uri=http://trino-coordinator:8080
internal-communication.shared-secret=a-long-random-string
For a local test, the official container saves you from installing Java and wiring paths. Mount the catalog directory and start it.
docker run --name trino -d -p 8080:8080 \
-v "$PWD/catalog:/etc/trino/catalog" \
trinodb/trino
The CLI ships inside the image; docker exec -it trino trino drops you into it, where SHOW CATALOGS confirms your files were read. A single node is perfect for learning; do not put it in front of twenty analysts.
Real scenarios
Joining operational data with the lakehouse
This is the classic case. Dimensions change all day in PostgreSQL while facts accumulate in Iceberg. Instead of replicating the dimension every hour, Trino reads the current version at query time.
SELECT
p.category,
count(DISTINCT o.customer_id) AS buyers,
sum(o.total) AS revenue
FROM lake.sales.orders o
JOIN postgres.public.products p
ON p.id = o.product_id
WHERE o.order_date >= DATE '2026-11-01'
GROUP BY p.category;
The dimension travels from PostgreSQL, but only the columns and rows the filter needs. The fact table is read from the lakehouse with partition pruning. The join happens in Trino.
Reconciling a migration
Before shutting down the old system, you need proof that the new one has the same data. One query compares counts and finds orphans without writing a Spark job.
SELECT coalesce(o.id, l.order_id) AS order_id
FROM postgres.public.orders o
FULL OUTER JOIN lake.sales.orders l
ON l.order_id = o.id
WHERE o.id IS NULL
OR l.order_id IS NULL;
Rows that appear only on one side are the work list. The result is small, the query is readable, and you never move the full datasets.
Auditing and exploration
An analyst can list schemas, describe tables, and query metadata from the same console, without opening three different admin tools.
Common mistakes
EXCEEDED_GLOBAL_MEMORY_LIMITorEXCEEDED_LOCAL_MEMORY_LIMIT. A join or aggregation built too large a state. Filter earlier, pre-aggregate, revisit the build side, or add cluster memory. Raising the limit without changing the query only delays the failure.Query exceeded maximum time limit. The limit isquery.max-run-time. There is usually aSELECT *on a huge table or a join that multiplies rows.- Pushdown is not happening. Look for implicit casts, functions on the filtered column, or a connector that does not support the operation.
EXPLAINis the only proof. Catalog 'x' does not exist. The properties file is not inetc/catalog, has a different name, or the coordinator was not restarted. Catalogs are static unless dynamic catalog management is enabled.- Identifiers that do not resolve. Trino lowercases unquoted identifiers. A schema created as
Salesat the source needs quotes if the connector is case-sensitive. - Type mismatches.
timestamp(3)againsttimestamp(6) with time zone, orvarcharagainstbigint, can block pushdown or fail the join. Cast explicitly. - Small files. Planning becomes more expensive than reading. Compact with the connector’s tooling.
- Cross-catalog joins are free until they are not. Joining two systems moves data over the network. If you do it every five minutes, replicate the dimension.
When not to use Trino, and a checklist
Do not use Trino as a transactional database. It is not OLTP, it has no row locks, and it is not built for thousands of concurrent writes. It is not an ETL orchestrator or a stream processor either: it can write results, but scheduling and exactly-once semantics belong elsewhere.
If your query fits in PostgreSQL and returns in milliseconds, adding Trino only adds a network hop. If you need sub-second latency for a public API, an interactive query engine is not the piece. And if the job is transforming petabytes every night, Spark remains the better fit.
Before you open the SQL editor, check this:
- Are the catalogs configured and visible in
SHOW CATALOGS? - Do the credentials for each connector work for the right user?
- Did you filter on the partition column without wrapping it in a function?
- Did you select only the columns you need?
- Did you read
EXPLAINto confirm pushdown? - Do the large tables have fresh statistics?
- Does the join use matching key types and a dimension that fits in memory?
- Does the query fit the memory and time limits of its resource group?
- Does the result stay in the cluster, or are you exporting millions of rows to the client?
- Is Trino the right fix, or do you need a materialized copy?
Trino does not move the warehouse to your desk. It moves the question to the data, and it forces you to accept that every cross-system join has a price. The skill is not avoiding that price, but knowing when it is worth paying.
Related articles
By relevance
Snowflake vs Databricks vs BigQuery: when to use each one (and when not to)
A hands-on comparison of Snowflake, Databricks and BigQuery: architecture, SQL, pricing, governance and real scenarios to choose well.
Spark hands-on: processing massive data without burning the cluster
Hands-on Apache Spark guide: architecture, DataFrames, partitions, shuffles, joins, caching, AQE, Parquet and Iceberg, and when not to use it.
Data Extraction, SQL & Automation in Go: Building Scalable Data Systems
Master data engineering in pure Go. Learn SQL querying, data extraction from multiple sources, transformation pipelines, automation workflows, and scientific data processing—all without external dependencies.
PostgreSQL Advanced: Data Extraction, Complex Analysis & Query Optimization at Scale
Master advanced PostgreSQL for analytical workloads. Learn extraction patterns, query optimization, materialized views, JSON analysis, and performance tuning for enterprise-grade data analytics.