---
metadata:
  - name: generator
    content: Diplodoc Platform v5.50.6
alternate:
  - https://ydb.tech/docs/en/concepts/query_execution.md?version=main
  - https://ydb.tech/docs/ru/concepts/query_execution.md?version=main
sourcePath: en/core/concepts/query_execution/index.md
---
> **Documentation Index:** Fetch the complete configuration index at https://ydb.tech/docs/en/llms.txt

# Query execution

YDB provides a unified interface for executing queries in the [YQL](https://ydb.tech/docs/en/yql/reference/index.md?version=main) language and a unified distributed execution engine. The same syntax and mechanisms allow accessing data of different nature: from rows in database tables to unbounded streams of events in topics and data in external systems.

From the user's perspective, queries are executed against three types of entities:

- [database tables](#tables) — transactional (OLTP) and analytical (OLAP) queries to data stored in YDB;
- [external data sources](#federated) — federated queries to data located outside YDB;
- [topics](#streaming) — queries to unbounded data streams: streaming queries and infinite queries to topics.

The general query processing flow, as well as basic concepts — sessions, transactions, retries, query language, and result sets — are described in the [Query execution process](https://ydb.tech/docs/en/concepts/query_execution/execution_process.md?version=main) section.

## Queries to database tables {#tables}

The main scenario is executing queries against [tables](https://ydb.tech/docs/en/concepts/datamodel/table.md?version=main) stored in YDB. The unified interface can efficiently handle a wide range of workloads — from high-load [transactional OLTP queries](https://en.wikipedia.org/wiki/Online_transaction_processing) to complex [analytical OLAP queries](https://en.wikipedia.org/wiki/Online_analytical_processing).

## Queries to external data sources (federated queries) {#federated}

[Federated queries](https://ydb.tech/docs/en/concepts/query_execution/federated_query/index.md?version=main) allow accessing data located in external systems without moving that data into YDB. Using YQL queries, you can read data from external DBMSs and object storages (S3), and also combine them with data in YDB tables.

For more details, see the [Federated queries](https://ydb.tech/docs/en/concepts/query_execution/federated_query/index.md?version=main) section.

## Queries to topics {#streaming}

Queries to [topics](https://ydb.tech/docs/en/concepts/datamodel/topic.md?version=main) allow processing unbounded data streams. Since the data stream is infinite, such a query does not complete after receiving a result, but runs until explicitly cancelled. There are two variants of such queries.

### Streaming queries

[Streaming queries](https://ydb.tech/docs/en/concepts/streaming-query/streaming-query.md?version=main) are the primary way of streaming data processing in production. They are created as persistent schema objects (`STREAMING QUERY`), read messages from topics as they arrive, write results to output topics or tables, and automatically recover from failures using [checkpoints](https://ydb.tech/docs/en/dev/streaming-query/checkpoints.md?version=main).

For more details, see the [Streaming queries](https://ydb.tech/docs/en/concepts/streaming-query/streaming-query.md?version=main) section and the description of [CREATE STREAMING QUERY](https://ydb.tech/docs/en/yql/reference/syntax/create-streaming-query.md?version=main).

### Queries to topics in table mode

You can also read data from a topic using a regular `SELECT` by specifying `STREAMING = "TRUE"` in the `WITH` clause. Without the `LIMIT` limit, such a query runs indefinitely, returning results to the client as messages arrive. Unlike streaming queries, it does not create a persistent schema object and does not recover from failures, so it is intended primarily for debugging and checking data in a topic.

For more details, see the [Streaming read from a topic](https://ydb.tech/docs/en/yql/reference/syntax/select/streaming.md?version=main) section.
