Data Virtualization and Federated Queries

architecture11 min한국어

#data-virtualization#federated-query#data-integration#trino#postgresql

Assume orders live in PostgreSQL, customers in MySQL, and click logs in Parquet files on object storage.

DataStoreTable
OrdersPostgreSQLshop.orders
CustomersMySQLcrm.customers
Click logsObject storage (Parquet)logs.daily_click

Answering “orders and clicks per VIP customer last month” means joining data from all three stores.
Splitting the query across the original sources instead of copying the data into one place is data virtualization, and its core capability is the federated query.

1. What the Two Terms Mean

1.1 Data Virtualization

Users query through a single access layer without knowing where or in what format the data is stored.
It is called virtualization because the data looks gathered in one place without any copy being made.

1.2 Federated Query

A federated query splits one query that spans several sources into per-source queries, runs them, and combines the results.
Data virtualization is mostly implemented with federated queries.

TermIn this post
Data virtualizationquerying data through one access layer without moving it
Federated querysplitting a query across sources, running the parts, and combining the results

2. Copying Data Together vs Querying It in Place

ETL (Extract, Transform, Load) extracts data from the sources, transforms it into a common format, and loads it into an analytical store such as a data warehouse. It usually runs on a schedule, such as daily or hourly.

① Copy into one place (ETL) ② Query in place (virtualization) PostgreSQL PostgreSQL MySQL MySQL Parquet Parquet warehouse daily copy query with SQL federation engine one SQL query Data moves: ① yes, ② no (only queries move)
① ETL copies data into one place and queries it there; ② data virtualization leaves data where it is and splits the query.
① ETL + warehouse② Data virtualization
Where data livescopied into one placewhere it already is
Point in time of datalast loadquery time (cache time if a cache is used)
Query speedgood for repeated analysisdepends on sources, network and execution plan
Adding a new sourcebuild a load pipelineadd a connector, handle permissions and schema differences
Load on sourcesat load timeon every query
Storage costsize of the copyno copy of the sources; only cache and intermediate results
  • When ETL fits: repeated large-scale analysis, reports that need data from a single point in time
  • When virtualization fits: exploratory queries, checking the latest state of the source, data that is hard to copy

3. How a Federation Engine Splits SQL

A federation engine does not store source data permanently; it connects to each source through a connector.
Users see one catalog per source, and intermediate data during execution stays in the engine’s memory or temporary storage.

-- Trino example: pg, mysql and lake are separate catalogs
-- Orders and clicks are aggregated per customer first, so the join does not double count
WITH monthly_orders AS (
  SELECT customer_id, count(*) AS order_count
  FROM pg.shop.orders
  WHERE created_at >= DATE '2026-09-01'
    AND created_at <  DATE '2026-10-01'
  GROUP BY customer_id
), monthly_clicks AS (
  SELECT customer_id, sum(clicks) AS click_count
  FROM lake.logs.daily_click
  WHERE day >= DATE '2026-09-01'
    AND day <  DATE '2026-10-01'
  GROUP BY customer_id
)
SELECT c.id, c.name,
       coalesce(o.order_count, 0) AS orders,
       coalesce(k.click_count, 0) AS clicks
FROM mysql.crm.customers c
LEFT JOIN monthly_orders o ON o.customer_id = c.id
LEFT JOIN monthly_clicks k ON k.customer_id = c.id
WHERE c.tier = 'VIP';

The engine works in this order.

  1. Analyze: use the catalogs to find which source each table belongs to.
  2. Plan: if the connectors support it, send tier = 'VIP' to MySQL and the date filter and per-customer count to PostgreSQL. For the Parquet files, the date filter narrows the partitions and blocks to read.
  3. Collect: receive the filtered results from each source.
  4. Combine: the engine performs the cross-source joins. Trino spreads this work across multiple nodes.
  5. Return the result
one SQL query federation engine split, collect, join MySQL WHERE tier = 'VIP' PostgreSQL date filter, count per customer Parquet date filter, needed columns filter first at the source
The federation engine pushes filters to each source so they filter first, and performs the cross-source join itself.

4. Pushdown Decides Performance

Handing work the engine would do over to the source is called pushdown.
Pushdown is the key optimization for reducing both transfer and processing.

Pushdown typeWhat goes to the sourceEffect
PredicateWHERE tier = 'VIP'the source filters rows first
ProjectionSELECT only the needed columnsless data transferred
Aggregationcompute count and sum at the sourcea few result rows instead of raw rows
Joinjoins between tables in the same sourcehandled by the source
LIMIT, sorttop N onlyless data transferred

If tier = 'VIP' cannot be pushed down, non-VIP customer rows also travel from MySQL to the engine.
The same SQL can run at very different speeds depending on which pushdowns the connector supports.
A function or type cast the source does not understand keeps a filter from being pushed down, so check the execution plan with EXPLAIN.

Without pushdown MySQL sends everything federation engine WHERE tier = 'VIP' 1M customer rows With pushdown MySQL WHERE tier = 'VIP' federation engine join only 300 VIP rows
Pushing the filter to the source (pushdown) greatly reduces the rows sent over the network.

5. Why Cross-Source Joins Are Costly

A join inside one database is handled by that database using its indexes and statistics.
A join between different databases cannot be handed to either source, so the federation engine receives data from both sides and processes it.

Take a query for last month’s orders from VIP customers.

SELECT c.name, o.id, o.amount
FROM mysql.crm.customers c
JOIN pg.shop.orders o ON o.customer_id = c.id
WHERE c.tier = 'VIP'
  AND o.created_at >= DATE '2026-09-01'
  AND o.created_at <  DATE '2026-10-01';

Assume there are 300 VIP customers, 10 million orders last month, and 4,500 of those orders belong to VIP customers.

5.1 Hash Join: Build a Hash Table from the Smaller Side

For cross-source joins, a federation engine mostly uses a hash join.

  1. build: read the smaller side, the 300 VIP customers, and build an in-memory hash table keyed by id.
  2. probe: read the larger side, the 10 million orders, row by row and look up each customer_id in the hash table.
  3. output: emit only the 4,500 orders whose customer is in the hash table.

Looking up one key in a hash table costs about the same regardless of the table’s size.
The orders are read only once, and only the 300 customers sit in memory.

MySQL 300 VIP customers PostgreSQL 10M orders last month federation engine hash table 300 customers keyed by id probe reads orders row by row result 4,500 orders ① build ② probe look up by customer_id ③
Hash join: build a hash table from the smaller side (300 customers), then read the larger side (10M orders) row by row and look each up.

5.2 Statistics: The Engine Must Know Which Side Is Smaller

The engine decides which side to build the hash table from by looking at statistics (row counts, distinct value counts).
Trino chooses the join order from statistics that connectors fetch from the sources.

  • With statistics: the hash table is built from the 300 customers. Only 300 rows go into memory.
  • Without statistics: the join order is left as written, and the hash table is built from the table on the right of the SQL, the 10 million orders. Memory use grows sharply, and the query fails if it exceeds the memory limit.
With statistics: smaller side is build build MySQL: 300 customers hash table 300 rows in memory probe PostgreSQL: 10M orders No statistics: right side of the SQL is build build PostgreSQL: 10M orders hash table 10M rows in memory probe MySQL: 300 customers
Without statistics, the hash table is built from the table on the right of the SQL. If the larger side becomes build, memory use grows sharply.

In Trino, check whether statistics exist with SHOW STATS FOR pg.shop.orders, and check which side is build with EXPLAIN.

When running on multiple nodes, statistics also decide how the hash table is distributed.

DistributionWhat it doesWhen it fits
broadcastcopy the whole build side to every nodethe build side is small
partitionedsplit both sides by join key and send the same keys to the same nodeboth sides are large

5.3 Dynamic Filtering: Filter Early at the Larger Source

With a hash join alone, PostgreSQL sends all 10 million orders from last month to the engine.
Only 4,500 of them end up in the result.
A dynamic filter turns the join keys collected during build into a filter on the probe side and sends it to the source.

  1. Collect the 300 VIP customer IDs during build.
  2. Turn the 300 IDs into a customer_id IN (...) filter and attach it to the PostgreSQL query. If there are too many IDs, send a range from the minimum to the maximum instead.
  3. PostgreSQL sends only the 4,500 orders from VIP customers.
Without dynamic filter PostgreSQL date filter only federation engine hash join 10M orders With dynamic filter PostgreSQL customer_id IN (300 IDs) federation engine 300 VIP customer IDs ① send 300 customer IDs ② 4,500 orders
A dynamic filter sends the customer IDs collected on the build side to PostgreSQL as a query filter, cutting the transfer from 10M rows to 4,500.

tier = 'VIP' is written in the SQL, so it can be pushed down at planning time, but the list of VIP customer IDs is known only after reading MySQL.
That is why a dynamic filter is created while the query is running.
Trino’s PostgreSQL and MySQL connectors wait a configured amount of time for the build side to finish before sending the probe-side query.
Whether the dynamic filter reaches the remote database’s SQL depends on the connector.

6. Open Source and Commercial Products

NameCharacteristics
Trinodistributed SQL query engine. Connects to RDBMSs, data lakes and search engines through connectors. Forked from Presto
Prestodistributed SQL engine that started at Meta
PostgreSQL FDWconnects tables in other databases as foreign tables inside PostgreSQL. A partial implementation of the SQL/MED (Management of External Data) standard
Apache Calcitequery parsing and optimization framework, used inside many engines
DuckDBin-process analytical database. Extensions connect PostgreSQL, MySQL and Parquet directly for joins
Dremio, Denododedicated data virtualization products with caching, acceleration layers and governance

6.1 What PostgreSQL FDW Covers

PostgreSQL connects tables in other stores as if they were its own through FDWs (Foreign Data Wrappers).
The FDWs shipped with PostgreSQL are postgres_fdw (other PostgreSQL servers) and file_fdw (files on the server).
MySQL, Oracle and SQL Server use separately installed community FDWs.

Since the order database is PostgreSQL, the customer table in MySQL can be connected with the community extension mysql_fdw.

CREATE EXTENSION mysql_fdw;
CREATE SERVER crm FOREIGN DATA WRAPPER mysql_fdw
  OPTIONS (host 'crm-db', port '3306');
CREATE USER MAPPING FOR CURRENT_USER SERVER crm
  OPTIONS (username 'reader', password '********');
CREATE SCHEMA crm_remote;
IMPORT FOREIGN SCHEMA crm LIMIT TO (customers) FROM SERVER crm INTO crm_remote;

-- Join the remote table as if it were local
SELECT o.id, c.name
FROM shop.orders o
JOIN crm_remote.customers c ON c.id = o.customer_id
WHERE c.tier = 'VIP';
What it can doLimits
query and join tables from other stores as if they were localjoins across different servers are processed by the single local PostgreSQL after fetching the data
postgres_fdw pushes filters, joins within the same server, aggregates and sorts to the remote server (check what is actually sent with EXPLAIN VERBOSE)pushdown support differs by FDW; for community FDWs, check what each version supports
group foreign tables as partitions to scan several remote servers at once (asynchronous execution)execution happens on one PostgreSQL server only; it cannot spread work across nodes like Trino
remote writes (INSERT, UPDATE, DELETE)no two-phase commit, so atomic commits across servers are not guaranteed
  • When FDW is enough: few sources, PostgreSQL-centric, and small remote transfers.
  • When a distributed engine (such as Trino) fits: many kinds of sources, or large analytical queries that must run across multiple nodes.
local PostgreSQL local table: shop.orders foreign: crm_remote.customers foreign table: other_pg.* mysql_fdw MySQL postgres_fdw another PostgreSQL joins run on this one server
PostgreSQL FDW: foreign tables connect other stores. Cross-source joins are processed by the single local PostgreSQL.

7. What Data Virtualization Cannot Solve

  • It naturally knows nothing about how data relates or what the data means. Whether cust_id in source A and customer_no in source B hold the same values, or what status = 3 means, is for the user to know.
  • It cannot guarantee one point in time across sources. Each source is read at a different moment with different transaction boundaries. Reading every source as of the same point in time needs a separate architecture.
  • It puts load directly on the source databases. Analytical queries run as-is on production databases. Connect to read-only replicas or limit query volume.
  • It cannot make slow sources fast. The result waits for the slowest source to respond.

Some products speed up repeated queries with caches and acceleration layers. In exchange, cache refresh intervals and storage costs have to be managed.

8. Semantic Layers on Top of the Federation Engine

A layer that defines metrics or concepts can sit on top of the federation engine.

semantic layer query by metric: monthly VIP revenue OBDA / virtual knowledge graph query by concepts and relations SQL data virtualization, federation engine many DBs, one SQL query DB A DB B files, lake
Semantic layers and OBDA run on top of data virtualization. Both generate SQL, and the federation engine runs that SQL.
  • Semantic layer: defines metrics and dimensions and generates SQL from those definitions.
  • OBDA (Ontology-Based Data Access): queries with the concepts and relations of an ontology and generates SQL through mappings.

When all the data is in one database, the semantic layer queries that database directly, so a federation engine is not required.

Common Misconceptions

  • ❌ With data virtualization, you no longer need ETL.
    ✅ Loading is better for repeated analysis or data from a single point in time. Using both is the better choice.
  • ❌ A federation engine handles cross-source joins as fast as joins inside one database.
    ✅ Cross-source joins need network transfer and engine processing. Pushdown and dynamic filters only reduce the transfer.
  • ❌ If you can query it with one SQL statement, the data is integrated.
    ✅ Only access is integrated. Field meanings and identifiers still have to be aligned.

Summary

  • Data virtualization lets you query through a single access layer without copying the sources, and makes federated queries possible.
  • A federation engine splits a query by source and performs cross-source joins and remaining operations itself.
  • Federated query performance depends on pushdown, source performance, the network, and the execution plan the federation engine builds from statistics.
  • PostgreSQL FDW fits small, PostgreSQL-centric setups; a distributed engine fits when sources and analytical workloads are large.

References