Skip to main content
Product11 min read

204 - Trino Query: analytics and insights

Plexara reaches customer data through Trino. What Trino is, how it maps to DataHub metadata, why OLAP queries finish fast, and how to export large results.

What you will take away from this lesson

In 203 - DataHub Search: describing the domain, the discover step pointed the agent at the right dataset and handed over any curated query templates that exist for it. This lesson is about what happens next: running the query. Plexara reaches data through Trino, which federates across whatever data stores the customer has connected.

The point of the lesson is not to teach SQL. Frontier models already write SQL well. The point is to understand how Plexara makes those queries accurate, where queries can come from during a session, and how agent-written queries become organizational knowledge over time.

Learning Objectives

  1. 01Describe what Trino is and why it is the single execution layer every Plexara data question passes through.
  2. 02Recognize that frontier models already know how to write SQL; Plexara makes their queries accurate by supplying schema and semantic context.
  3. 03Identify the three sources a query in a Plexara session can come from (agent-authored, curated in the catalog, or synthesized from prior sessions) and why curated queries still matter even when the agent could write one itself.
  4. 04Read the OLAP vs OLTP distinction and know why running the wrong shape against the wrong store is the most common cause of a ninety-second query.
  5. 05Know when to call trino_query vs trino_export, and understand how agent-written queries feed the knowledge pipeline so future sessions start smarter.

A mental model for Trino

Trino is a distributed SQL engine that federates queries across many backends. Plexara uses Trino as the single execution layer every MCP data question passes through. Whether the underlying store is PostgreSQL, OpenSearch, Oracle, Snowflake, or any other Trino-compatible connector, the agent writes SQL once and Trino routes it to the right catalog.

The practical benefit: the agent does not have to learn half a dozen dialects. The customer does not have to standardize on a single vendor. The Plexara MCP server does not need to know, in advance, which kinds of stores it will end up talking to.

Trino is the single execution layer; the backends differ

The agent writes one SQL dialect (Trino's) and calls trino_query. Trino routes the query to the right catalog and handles whatever the underlying backend speaks. The customer's data estate can be any combination of the following:

  • OLTP row store

    Row-oriented, indexed on primary keys.

    PostgreSQL, MySQL, Oracle, SQL Server.

  • OLAP column store

    Columnar, aggregation-optimized, often with pushdowns.

    OpenSearch, ClickHouse, Snowflake, BigQuery.

  • Object storage

    File-based, often Parquet; scanned at query time.

    S3, GCS, Azure Blob (through the Hive or Iceberg connectors).

Plexara does not impose a specific backend. The same MCP server works against whichever combination of Trino-compatible stores the customer has already invested in.

How Trino tables map to DataHub entities

Every Trino table has a corresponding DataHub entity, keyed by URN. The URN includes the Trino catalog, schema, and table, which lets the agent go from a query result back to the catalog's owners, tags, glossary terms, lineage, and curated queries for that entity. This mapping is what makes a query result interpretable, not just readable. It is also what lets the enrichment described in the previous lesson attach automatically.

Where queries come from: three sources

A frontier model already knows how to write SQL. That capability is in the training data. What it does not know, on its own, is your schema, your naming conventions, your glossary, or which column actually stores the number you care about. Plexara supplies that context, which is why agent-authored queries on a Plexara session tend to be correct on the first try rather than after three rounds of iteration.

Within any given session, a query can originate from one of three sources. All three are legitimate; which one runs depends on what the question is and what the catalog already knows.

Three places a query in a Plexara session can come from

  • Written by the agent from scratch

    When: No curated query fits and memory has nothing relevant.

    The frontier model writes SQL using the schema and semantic context Plexara surfaced during the discover step. The schema tells it the column names and types. The catalog tells it what the columns mean. The query produced this way is usually correct on the first try because it is grounded in both.

  • Curated query from the catalog

    When: datahub_get_queries returned one or more templates for the matched dataset.

    The agent uses a known-good query that has already been written, tested, and annotated with performance characteristics. Deterministic input, deterministic result. When a curated query exists for the shape of the question, using it is the default.

  • Recalled from a prior session

    When: The agent (or a teammate) previously wrote a query for a similar question and it was captured.

    Memory and the knowledge pipeline surface queries from prior sessions when they match the current question, letting the current session skip the rediscovery step entirely.

A customer with no curated queries at onboarding is fine. The agent writes new ones as needed, and over time the pipeline covered in 206 promotes the ones worth keeping into catalog-level documentation.

Why curated queries still matter

If the frontier model can write SQL, it is reasonable to ask why a catalog of curated queries exists at all. Two answers. One is reproducibility, which matters most for anything that will be reported upward or referenced later. The other answer is less obvious but more important over time: a curated query is itself a layer of documentation.

A known query produces a known result

The curated template has already been run, reviewed, and benchmarked. Two different users asking the same question get the same answer down to the row. Important for anything that will be reported up the chain.

The query itself is documentation

Schema descriptions are one layer of documentation. Glossary terms are a second. The construction of a query is a third: the joins, filters, and aggregations describe the relationships and business rules in executable form. A well-authored curated query teaches future agents (and future humans) how the data actually fits together.

Query shape: OLAP vs OLTP

The most common cause of a slow Plexara session is running the wrong shape of query against the wrong kind of store. Point lookups belong on row-oriented indexed stores; aggregations belong on columnar analytical stores. Running either against the wrong backend is where eighty-second queries come from, and the agent has no way to recover from a bad shape without rewriting the query.

The operating manual the agent receives from platform_info tells it which catalog is appropriate for which shape. A deployment whose OLAP layer is OpenSearch has that documented; a deployment that uses ClickHouse or Snowflake instead has its own version of the same guidance. The agent does not have to guess; it reads the manual.

Query shape determines which store should answer

  • Point lookup: fetching one specific row by a unique identifier (show me customer 42, get order #12345, current inventory at store 7)

    Right store: Indexed row store (PostgreSQL and similar).

    Wrong store: Columnar OLAP store: has to read many rows to find one.

    Cost when mismatched: Seconds instead of milliseconds, sometimes worse at large volume.

  • Aggregation: rolling up many rows into a summary (revenue by region for a year, redemption rates by tier, average order size by month)

    Right store: Columnar OLAP store with pushdown support (OpenSearch, ClickHouse, Snowflake).

    Wrong store: OLTP row store: has to scan every row and aggregate in memory.

    Cost when mismatched: A ninety-second GROUP BY on a large table, sometimes timing out entirely.

The agent does not have to guess which store to use. The agent_instructions block from platform_info tells it which catalog is appropriate for which shape, and each customer's manual is tuned to the backends they have connected.

Pushdown and connector-native query paths

When Trino can push an operation down to the underlying backend, it runs the operation natively and returns only the result. When it cannot push down, it reads rows back through the network and aggregates in-memory. For small tables this does not matter; for large tables it is the difference between a one-second query and a ninety-second one.

Some connectors expose escape hatches for cases where standard Trino SQL will not push down cleanly. The OpenSearch connector exposes a raw_query table function that lets the agent compose native OpenSearch Query DSL for aggregations. The customer's agent_instructions describe which escape hatches are appropriate for which backend; the benchmarks are measured, not assumed.

Large result sets: trino_query vs trino_export

Not every query returns a handful of rows. Some return thousands. Getting the result shape right at query time, and choosing between trino_query and trino_export, is the difference between an efficient session and one that exhausts its context window on a single lookup.

Agent-authored queries become organizational knowledge

Curated queries are often thought of as something the organization must preload into the catalog. In practice the flow is bidirectional. An agent that writes a new or derivative query during a session can surface it as an insight, and an administrator can promote it through the review pipeline into a catalog-level curated template. The next person asking a similar question gets that query handed to them by datahub_get_queries.

This matters for organizations starting from scratch. A customer with no curated queries on day one is not missing anything; the curated library builds itself from real usage. Every useful question the agent answers is a candidate future template.

Where this leads

Queries produce results. Small results live in the conversation. Large results, and anything worth keeping past the current session, belong in an asset. The next lesson covers the asset system.

Key terms

Nine terms cover the vocabulary you will see across Trino results, the operating manual, and any discussion of query performance on a Plexara session.

Key Terms

Trino
A distributed, federated SQL engine. Plexara uses Trino as the single execution layer through which every data question reaches the underlying backends. The agent writes one SQL dialect; Trino routes to whichever catalog is connected.
Catalog (Trino sense)
A named connection to a backend store inside Trino. A single Plexara deployment can have many Trino catalogs (for example, one pointing at PostgreSQL, one at OpenSearch, one at S3 via Iceberg), each exposed as its own top-level namespace.
Point lookup
Fetching one specific row by a unique identifier (for example, show me customer 42, get order #12345, current inventory at store 7). Cheap on an indexed row store, expensive on a columnar OLAP store.
Aggregation
Rolling up many rows into a summary (for example, revenue by region for a year, average order size by month). Cheap on a columnar OLAP store with pushdown support, expensive on an OLTP row store.
OLTPonline transaction processing
Row-oriented, indexed workloads. Dominated by point lookups, single-entity reads, and small writes. Well suited to stores like PostgreSQL, MySQL, Oracle, SQL Server.
OLAPonline analytical processing
Column-oriented, aggregation-heavy workloads. GROUP BY, percentiles, time-bucketed rollups. Well suited to stores like OpenSearch, ClickHouse, Snowflake.
Pushdown
When Trino delegates part of a query to the underlying backend (filter, aggregation, top-N) instead of reading rows back through the network. The difference between a one-second query and a ninety-second query on large datasets.
Curated query template
A pre-written, pre-benchmarked query stored against a dataset in DataHub. Retrieved via datahub_get_queries. Two benefits: known inputs produce known results, and the query construction itself documents how the data fits together. Agent-authored queries can be promoted into curated templates via the knowledge pipeline in 206.
trino_export
The tool that runs a Trino query and writes the result to a persisted asset (CSV, JSON, Markdown) instead of returning rows in the conversation. The primary way to keep large result sets out of the token budget (102).