Presto and Trino: Querying Everything From Anywhere
Learn how PrestoDB and Trino federate SQL across data sources, what connector pushdown can and cannot reduce, and how to compare federation with materialized data.
PrestoDB and Trino are separate projects descended from the original Presto engine. They run federated SQL through connectors, but query results and intermediate data still cross networks, and each connector has its own pushdown and source-system limits. Compare them with materialized data using the versions, connectors, workload, and measurements that match your environment.
Presto and Trino: Querying Everything From Anywhere
You have data in S3, in PostgreSQL, in MongoDB, in Kafka, in your data warehouse, and in three different MySQL instances from acquired companies. Your analysts need to join across all of it. What do you do?
PrestoDB and Trino answer this with federated query engines: connectors let one SQL query read from multiple systems. That can avoid a separate consolidation step for some analyses, but it does not make data movement disappear. Workers read from the sources, exchange intermediate results, and return output over the network. The source systems still handle whatever reads the connector sends them.
The Problem: Data Silos
Most enterprises end up with data scattered across systems that do not talk to each other. Your BI tool connects to the warehouse. Your data scientists query the data lake directly. Your operational reports hit the OLTP database directly. Customer data lives in three different systems depending on which acquisition it came from.
Consolidating everything into one system is expensive, slow, and politically difficult. Different teams own different systems. Regulatory requirements mandate data residency. Some data changes too frequently to replicate.
PrestoDB and Trino support a virtual approach: send the query to the data instead of first moving every source into one warehouse.
Architecture: Coordinator and Workers
Presto and Trino use a classic distributed query architecture. The coordinator receives SQL, parses and plans the query, schedules work across workers, and returns results. Workers execute tasks in parallel, reading from their assigned data sources and exchanging intermediate results over the network.
-- Query across multiple sources in a single SQL statement
SELECT
c.customer_name,
c.region,
SUM(wh.order_amount) AS warehouse_revenue,
SUM(ec.cart_value) AS ecommerce_revenue,
SUM(wh.order_amount) + SUM(ec.cart_value) AS total_revenue
FROM mysql_customers.crm.customers c
JOIN redshift_sales.warehouse_orders wh ON c.customer_id = wh.customer_id
JOIN glue_catalog.ecommerce.transactions ec ON c.customer_id = ec.customer_id
WHERE c.region = 'EMEA'
GROUP BY c.customer_name, c.region;
The coordinator knows where each catalog’s data lives. It asks connectors to push down supported filters and other operations. When pushdown works, it can reduce bytes read and transferred; support depends on the connector, source, operation, and query shape. Workers may still transfer large scans or join inputs across the network.
Trino Architecture
flowchart TD
subgraph Client[Client]
BI[BI Tool / JDBC / CLI]
end
subgraph Coordinator[Coordinator Node]
SQL[SQL Parser]
PLAN[Query Optimizer]
SCHEDULE[Task Scheduler]
METRICS[Metrics]
end
subgraph Workers[Worker Nodes]
W1[Worker 1]
W2[Worker 2]
W3[Worker N]
end
subgraph Catalogs[Data Catalogs]
HIVE[Hive / Glue]
POSTGRES[PostgreSQL]
REDSHIFT[Redshift]
S3[S3 / Object Storage]
KAFKA[Kafka]
end
BI -->|SQL query| Coordinator
Coordinator -->|dispatch| W1
Coordinator -->|dispatch| W2
Coordinator -->|dispatch| W3
W1 <-->|exchange| W2
W2 <-->|exchange| W3
W1 -->|read| HIVE
W2 -->|read| POSTGRES
W3 -->|read| REDSHIFT
W1 -->|read| S3
W2 -->|read| KAFKA
The coordinator parses SQL and creates a distributed query plan. Workers exchange intermediate results with each other. Each worker reads from the connectors assigned to its tasks.
Presto Versus Trino: The Fork
The original Presto engine was created at Facebook and open-sourced in 2013. The project split into separately developed communities in 2019: one continued as PrestoDB, while the creators’ community used the name PrestoSQL. PrestoSQL was renamed Trino in December 2020. The projects share ancestry, but they have separate code, releases, connector implementations, and upgrade paths. See the Trino rebrand history for the Trino community’s account.
As of November 24, 2026, the project download pages list PrestoDB 0.299 and Trino 484; see the PrestoDB 0.299 notes and Trino 484 notes. These version numbers describe the upstream projects at that date, not every vendor distribution. Connector support and maturity are version-specific: check the documentation for the exact connector and release, including read/write support, pushdown, type mappings, and known limitations. Community help and commercial support also depend on the project or distribution you deploy; verify the available support channel and contract with its provider.
Query Execution: How It Works
When you submit a query, the coordinator parses the SQL and creates a logical plan. The optimizer reorganizes joins, pushes down predicates, and determines which data to read from which connectors. The physical plan divides work into stages that run on workers.
EXPLAIN (TYPE DISTRIBUTED)
SELECT
date_trunc('week', o.order_date) AS week,
p.category,
COUNT(DISTINCT o.customer_id) AS unique_customers,
SUM(o.total_amount) AS revenue
FROM redshift.analytics.orders o
JOIN presto.default.products p ON o.product_id = p.id
WHERE o.order_date >= CURRENT_DATE - INTERVAL '30' DAY
GROUP BY 1, 2
ORDER BY 4 DESC;
The EXPLAIN output shows the distributed plan: which stages run on which workers, how data is partitioned, and what pushes down to connectors. Understanding explain plans is essential for tuning Trino queries at scale.
Connectors: Talking to Everything
The connector system is what makes Trino powerful. Each connector understands how to read (and sometimes write) from a specific data source.
The Hive connector reads from data lakes using Hive metastore or AWS Glue as the catalog. It supports Parquet, ORC, JSON, and text files. It pushes filter predicates down to file level when possible.
-- Query a data lake table managed by Glue
SELECT *
FROM hive.production.clickstream_events
WHERE event_date = DATE '2025-03-27'
AND event_type = 'purchase'
LIMIT 100;
The PostgreSQL connector creates a virtual schema that maps to PostgreSQL tables. Queries run directly against PostgreSQL, with predicate and aggregation pushdown.
-- Join PostgreSQL dimension with Redshift facts
SELECT
p.product_name,
p.inventory_count,
r.revenue_30d
FROM postgresql.inventory.products p
LEFT JOIN (
SELECT product_id, SUM(amount) AS revenue_30d
FROM redshift.analytics.sales
WHERE sale_date >= CURRENT_DATE - 30
GROUP BY product_id
) r ON p.product_id = r.product_id
WHERE p.inventory_count < 10;
Memory management is critical. Trino processes data in memory across workers, and queries that exceed memory limits fail. The task.max-memory configuration controls per-task memory. For large joins or aggregations, you may need to spill to disk or increase memory allocation.
Performance Characteristics
Trino can work well for filtering and aggregating data across sources, especially when the relevant connectors can apply the filters close to the data. Pushdown is not guaranteed: inspect EXPLAIN and source-side query metrics. A source may still scan many files or rows, and cross-source joins can move substantial intermediate data through Trino workers.
Joins between large tables are expensive. If both sides of a join are massive, you need to broadcast one side to all workers or shuffle data by join key. Broadcasting works when one side fits in worker memory. Shuffling works for larger datasets but requires network transfer.
Compare federation with materialization
There is no useful universal benchmark for federation: results depend on the source, connector, query plan, data layout, cache state, network, and competing workload. Run this comparison on a representative data snapshot and record measurements from your own environment.
- Write one logical query and verify its result with row counts and a deterministic checksum or equivalent comparison.
- Run it through federation. Capture the query plan, elapsed time, Trino bytes and rows read/written, exchange bytes, and source-side bytes, CPU, and query time where available.
- Use the same snapshot to materialize the needed source tables with your ETL tool, such as Spark or Beam, then run the same logical query against that destination. Record ETL duration, bytes moved, destination storage, query-engine metrics, and freshness delay.
- Repeat trials under documented cold-cache and warm-cache conditions. Record concurrency and other load, then report the individual runs and a chosen summary such as median and p95. Do not compare a warm materialized table with a cold federated scan without saying so.
| Measurement | Federation | Materialize with ETL |
|---|---|---|
| Versions, connector, source snapshot | Record | Record |
| Result check (row count/checksum) | Record | Record |
| End-to-end elapsed time | Record | Record |
| Source rows/bytes read and source load | Record | Record |
| Network bytes moved and Trino exchange bytes | Record | Record |
| ETL duration, destination storage, freshness delay | Not applicable | Record |
| Trial conditions, including cache and concurrency | Record | Record |
A small local measurement
I ran one small comparison on November 24, 2026 to put the procedure above into practice. The host was x86_64 Linux 7.0.0-43-generic on an AMD Ryzen 9 5950X (16 cores, 32 threads) with 30 GiB of RAM and Docker Engine 29.8.2. The official trinodb/trino:484 image ran Trino 484 with Temurin OpenJDK 25.0.4 and a 3 GiB JVM heap. Three postgres:17-alpine containers ran PostgreSQL 17.12: separate source databases for orders and customers, plus a destination database. All four containers shared one Docker network on this host; there were no CPU or memory limits.
The generated snapshot had 1,000,000 orders and 100,000 customers. Orders used order_id 1 through 1,000,000, customer_id = ((order_id - 1) % 100000) + 1, and amount_cents = (order_id * 7919) % 100000; the table had a primary key on order_id and an index on customer_id. Each customer belonged to segment-((customer_id - 1) % 10), with a primary key on customer_id. PostgreSQL reported 94 MB for the orders table including its indexes and 6,568 kB for customers. The Trino PostgreSQL connector read the two source databases through separate catalogs.
The three catalogs used the Trino PostgreSQL connector. For example, orders.properties contained the following; the other catalogs used their own Docker network alias and database name:
connector.name=postgresql
connection-url=jdbc:postgresql://pg-orders:5432/orders
connection-user=bench
connection-password=bench
The source tables were built with deterministic values and then analyzed:
CREATE TABLE public.orders (
order_id bigint PRIMARY KEY,
customer_id integer NOT NULL,
amount_cents bigint NOT NULL
);
INSERT INTO public.orders
SELECT g::bigint,
((g - 1) % 100000 + 1)::integer,
((g::bigint * 7919) % 100000)::bigint
FROM generate_series(1, 1000000) AS g;
CREATE INDEX orders_customer_idx ON public.orders(customer_id);
ANALYZE public.orders;
CREATE TABLE public.customers (
customer_id integer PRIMARY KEY,
segment varchar(16) NOT NULL
);
INSERT INTO public.customers
SELECT g::integer, ('segment-' || ((g - 1) % 10)::text)::varchar(16)
FROM generate_series(1, 100000) AS g;
ANALYZE public.customers;
I created the materialized table with this one-time Trino CTAS, which took 7.157 seconds and wrote 1,000,000 joined rows. PostgreSQL reported 65 MB for the destination table:
CREATE TABLE materialized.public.orders_enriched AS
SELECT o.order_id, o.customer_id, o.amount_cents, c.segment
FROM orders.public.orders o
JOIN customers.public.customers c ON o.customer_id = c.customer_id;
The measured query returned a count and cents total for each segment. The two versions were:
-- Federation: join two PostgreSQL catalogs at query time.
SELECT c.segment, count(*) AS order_count, sum(o.amount_cents) AS total_cents
FROM orders.public.orders o
JOIN customers.public.customers c ON o.customer_id = c.customer_id
GROUP BY c.segment
ORDER BY c.segment;
-- Materialized: query the joined table produced by CTAS.
SELECT segment, count(*) AS order_count, sum(amount_cents) AS total_cents
FROM materialized.public.orders_enriched
GROUP BY segment
ORDER BY segment;
The two queries returned the same ten rows, each with 100,000 orders and the same total_cents. I ran two warm-ups per query, then seven measured trials per query in alternating order, with one query at a time and no concurrent benchmark workload. I did not flush operating-system or database caches, so these are warm-path timings. The reported elapsed time is the wall time from a small HTTP client on the host, including Trino planning, execution, and result delivery.
| Query | Individual client times (seconds) | Median |
|---|---|---|
| Federated join | 0.659, 0.613, 0.581, 0.567, 0.578, 0.561, 0.566 | 0.578 |
| Materialized table | 0.465, 0.395, 0.379, 0.385, 0.388, 0.380, 0.378 | 0.385 |
Trino reported 1,701,883 bytes of internal stage-exchange input for the federated query and 1,761 bytes for the materialized query. Those are Trino exchange metrics, not total network transfer to the PostgreSQL sources. The run did not measure source-side network bytes, CPU, or disk I/O, and Trino reported no physical-input byte count for these connector reads. The distributed plan kept the join and group aggregation in Trino; the materialized query skipped the cross-catalog join because CTAS had already stored the joined rows.
For this one setup, the 7.157-second CTAS cost divided by the 0.1924-second median query-time difference gives about 38 repeated queries to offset the initial build time. That is only an estimate; it excludes storage, source load, refresh work, and freshness requirements. This was a single-node, same-host exercise with one workload and warm caches. It does not establish that federation or materialization will be faster in another deployment.
For repeated queries, estimate total cost over a stated period as the one-time or recurring ETL cost plus materialized storage and query costs, compared with the measured per-query federation cost. Treat that arithmetic as an estimate based on your measurements, not as a benchmark result. Include source-system impact and freshness requirements in the decision.
Analytical queries—aggregations, window functions, complex joins across multiple filtered sources—play to Trino’s strengths. Transactional queries that return single rows or update small amounts of data are not what Trino is designed for.
Trino, PrestoDB, and Materialized Data
| Aspect | Trino | PrestoDB | Materialized/ETL alternative |
|---|---|---|---|
| Project/release | Separate project; upstream 484 on 24 Nov 2026 | Separate project; upstream 0.299 on 24 Nov 2026 | Depends on selected engine |
| Connector behavior | Check support in the chosen release and connector docs | Check support in the chosen release and connector docs | Depends on source and ETL connector |
| Support | Community channels or distribution vendor | Community channels or distribution vendor | Depends on engine and provider |
| Typical fit | Interactive federation and multi-source SQL | Interactive federation and multi-source SQL | Repeated queries, controlled freshness, or reusable curated datasets |
For multi-source federation, Trino or PrestoDB. For single-source workloads, use the native engine (Spark for batch ETL, Flink for streaming).
When to Use Trino
Trino is a fit when one SQL layer needs to read across sources without first maintaining a consolidated copy. Federation still transfers rows and intermediate results, and can add load to source systems. Data virtualization, cross-source joins, and ad-hoc data-lake exploration are reasonable use cases when the connectors and source capacity suit the workload.
Trino can also serve interactive BI queries on a data lake while Spark handles ETL and batch processing. Check the storage format, catalog, source load, and query mix before choosing that split.
Trino is not an operational database. It does not handle high-frequency inserts or updates well. It does not provide ACID transactions across sources. It is a query engine, not a storage system.
Trino Production Failure Scenarios
Coordinator OOM on complex query
A user submits a query with a 10-way join across large tables. The coordinator holds the entire query plan and intermediate results in memory. The coordinator runs out of heap and crashes. All running queries fail, and the cluster becomes unavailable.
The coordinator is the single point of failure in a Trino cluster. Unlike workers, which run tasks in isolation, the coordinator maintains the full query state across all stages. This includes the parsed SQL tree, the distributed query plan, statistics from each connector, and any partial results waiting for the final stage. A query with many joins creates a large query plan object that stays in memory throughout execution. If the query also involves large intermediate results from group-by operations, the coordinator’s heap fills quickly.
When the coordinator OOMs, it does not gracefully drain. Running queries lose their coordinator and time out. The workers continue processing whatever tasks were in flight, but without a coordinator to collect results, those tasks produce orphaned data. Restarting the coordinator requires reloading catalog metadata and reconnecting to workers, which takes 30-60 seconds in a typical deployment. During that window, no queries can be accepted.
Mitigation: Set query.max-memory to limit per-query memory. Set query.max-total-memory-per-query for distributed memory. Monitor coordinator heap usage and alert before it exceeds 80%. For very large queries, force task.max-memory-per-node limits. Also configure query.max-run-time so runaway queries are killed before they exhaust the coordinator. On restart, Trino re-registers workers automatically, but monitor that re-registration completes before allowing new query submissions.
Memory spill causing query timeouts
A query tries to join two large tables that don’t fit in worker memory. Trino spills intermediate results to disk, but disk is slow. The query runs for 30 minutes and times out before completing.
Trino processes data entirely in memory. When a join produces intermediate rows that exceed a worker’s memory allocation, Trino writes those rows to disk using a spill-to-disk mechanism. The key word is slow—disk I/O is orders of magnitude slower than memory access, and the spill files are stored on the worker’s local filesystem. A join that would take seconds in memory can stretch into minutes or hours when spilling kicks in. The effect compounds when multiple workers are spilling simultaneously, because they all compete for the same disk throughput.
The timeout is not just about slowness. Trino’s query.max-execution-time limits how long a query can run before it is killed. If the estimated runtime exceeds this limit, the query is terminated before it can finish. Even when the timeout is generous, a spilling query that eventually completes consumes worker resources that other queries need. Workers under memory pressure also trigger garbage collection more frequently, which adds CPU overhead on top of the disk I/O overhead.
Mitigation: Estimate memory requirements before running large joins. Use EXPLAIN to see if a join will broadcast or shuffle. For very large joins, pre-aggregate one side or use approximate algorithms (HyperLogLog for count-distinct). Monitor spilled_memory and spilled_files metrics. Set spiller.spill-path to a dedicated fast disk (SSD) rather than a shared network mount. If you see repeated spilling, consider increasing worker memory or reducing concurrency—the memory budget per query shrinks as more queries run in parallel.
Predicate pushdown failure causing connector overload
A user submits a query with a date filter event_date = '2025-03-27'. The PostgreSQL connector fails to push down the predicate because the column type doesn’t match. The connector reads all rows from PostgreSQL and transfers them to workers, overwhelming the PostgreSQL instance.
Predicate pushdown in Trino operates at two levels. The optimizer decides which predicates can be pushed to each connector based on the query plan and connector capabilities. The connector then decides whether it can actually apply those predicates when generating the native query. A common failure mode is a type mismatch at the connector level. If the source column is timestamp without time zone but the query filter uses a date literal, the PostgreSQL connector may decide it cannot safely push the predicate and instead pulls all rows for the connector to filter in Trino. The resulting data transfer from PostgreSQL to Trino can be orders of magnitude larger than expected.
This can be hard to spot because the query may still return correct results, only after reading and transferring far more data than expected. The PostgreSQL instance carries that read load while Trino workers spend CPU filtering rows that could have been excluded earlier. Check the plan and compare connector rows read with rows returned before assuming a filter is pushed down.
Mitigation: Test connector pushdown with EXPLAIN. Verify column types match between the query filter and the source. For connectors with poor pushdown, add application-level filtering in the query itself. Monitor connector.read.rows vs task.output.rows to detect pushdown failures. When writing filters, cast literals to match the source column type explicitly—using date '2025-03-27' instead of a string, or timestamp '2025-03-27 00:00:00' for timestamp columns. Check the Trino documentation for each connector’s pushdown limitations, as some connectors (like Kafka) have more restricted pushdown capabilities than relational databases.
Catalog misconfiguration exposing wrong data
A new catalog is added to Trino for a development data source. The catalog name dev_postgres is similar to prod_postgres. A user accidentally queries the wrong catalog and gets stale development data in a production report.
The risk here is not a technical misconfiguration—it is an organizational one. Trino’s catalog layer is flat, which means all catalogs are visible to all users by default once they have cluster access. There is no automatic mechanism that prevents a user from running SELECT * FROM dev_postgres.crm.customers in a production BI dashboard. The query will execute. It will return data. It will just be the wrong data. In organizations where dev and prod databases look similar, this mistake is easy to make and hard to catch without active monitoring.
The consequences compound when teams share BI tools with saved queries. A dashboard saved in a production workspace might reference a catalog name that a developer changed last week. The dashboard fails silently in some places and returns wrong results in others. By the time the error is discovered, the incorrect data may have influenced business decisions.
Mitigation: Use consistent naming conventions (prefix catalogs with environment: prod_, dev_). Restrict catalog access by role. Add query comments that must specify the target environment. Audit query logs for cross-environment joins. In Trino, you can use the ALWAYS Grant system to control catalog visibility per role. For high-sensitivity environments, consider a validation layer that parses incoming queries and rejects those targeting non-approved catalogs. Some teams also add a query_context comment requirement: queries without a comment referencing the target environment are routed to a sandbox cluster that has no access to production catalogs.
Conclusion
PrestoDB and Trino let teams query multiple sources through one SQL interface. That can avoid copying data for some questions, but federation still uses network capacity and source resources. Materialization may be a better fit when queries repeat often, when freshness can be bounded, or when source systems cannot absorb analytical scans.
Quick Recap
- Trino and PrestoDB can query across sources, but reads and intermediate results still use the network.
- The coordinator parses and optimizes SQL; workers execute tasks and exchange intermediate results.
- Predicate pushdown is critical for performance: verify it works with
EXPLAINbefore running large queries. - Memory limits prevent single queries from crashing the cluster—set
query.max-memory-per-node. - Use RBAC and catalog naming conventions to prevent cross-environment queries.
- For single-source workloads, use the native engine (Spark, Flink) instead of Trino.
For teams working across data silos, federation can provide a shared query layer without requiring every dataset to be copied first. Check pushdown, source load, freshness, and connector limits before treating it as a replacement for materialized data.
Trino Observability
Key metrics to monitor:
-- Query-level performance metrics from Trino's built-in tables
SELECT
query_id,
state,
total_rows,
total_bytes,
execution_time_ms,
peak_memory_bytes
FROM system.runtime.queries
WHERE state = 'FAILED'
ORDER BY execution_time_ms DESC
LIMIT 10;
-- Worker health
SELECT
worker_id,
tasks_running,
tasks_blocked,
memory_usage_bytes,
cpu_usage_pct
FROM system.runtime.worker_nodes;
Monitor per query: rows scanned, bytes scanned, execution time, peak memory. Alert on: coordinator heap > 80%, query failure rate > 5%, worker memory pressure. Track query.stats.output_bytes to detect queries returning unexpectedly large results (potential data leak).
Trino Security Checklist
- Enable LDAP or OAuth authentication for all users
- Configure RBAC for catalog and schema access
- Restrict access to system catalog (
information_schema) by role - Validate catalog names: use environment prefixes (
prod_,dev_) to prevent cross-environment queries - Enable query audit logging with user, query text, and source IP
- Set memory limits per query (
query.max-memory-per-node) to prevent single-query OOM from affecting cluster - Encrypt connections between workers (internal communication) and to data sources
Trino Anti-Patterns
Using Trino as an operational database. Trino is not designed for high-frequency single-row lookups or write workloads. If you find yourself running millions of small queries through Trino, use the native database or add caching (Redis, Hive Metastore) instead.
Large broadcast joins without memory limits. Forcing a broadcast join on a 100GB table overwhelms worker memory. The query fails, but not before causing GC pressure on all workers. Always check EXPLAIN for memory estimates before running large joins.
No catalog access control. If any user can query any catalog, a misconfigured BI tool could hit production systems. Always configure RBAC per catalog and validate in staging first.
For large-scale batch processing, see Apache Spark. For portable streaming and batch pipelines, read about Apache Beam.
Official project references
Category
Related Posts
AWS Data Services: Kinesis, S3, Glue, Athena, Redshift
Follow an order event from Kinesis Data Streams through S3 to Athena or Redshift, adding Glue when transformation or shared catalog metadata helps.
Azure Data Pipelines with Event Hubs and Synapse
Follow live events and scheduled data through Azure processing, Data Lake Storage Gen2, and Synapse, with a clear choice between stream and batch paths.
Data Lake Architecture: Storage and Workload Choices
Learn how data lakes organize analytical data, choose partitions and table formats, and plan retention, access, quality, and cost controls.