> ## Documentation Index
> Fetch the complete documentation index at: https://docs.bytebase.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Query

<Info>
  By default, SQL Editor allows executing both read (SELECT) and write (DDL/DML) SQL statements.

  You can restrict SQL Editor to read-only mode by configuring [Statement Execution Mode](/change-database/environment-policy/overview#statement-execution-mode). In read-only mode, if you attempt to run DDL or DML change queries, SQL Editor will prompt you to create a new issue to start the [SQL change workflow](/change-database/change-workflow).

  Workspace Admins and DBAs can always execute any SQL statements in [Admin Mode](/sql-editor/admin-mode).
</Info>

## Autocomplete

<img src="https://mintcdn.com/dbx/yhR4_AKNF_MEUOA1/content/docs/sql-editor/autocomplete.webp?fit=max&auto=format&n=yhR4_AKNF_MEUOA1&q=85&s=acec6b3133fba3d91911130b2e328004" alt="autocomplete" width="915" height="416" data-path="content/docs/sql-editor/autocomplete.webp" />

Autocomplete depends on WebSocket. If you access Bytebase via a gateway, you need to enable WebSocket there. Here is a NGINX configuration:

```nginx theme={null}

http {
    server {
        ...

       location ~ ^/(v1:adminExecute|lsp) {
            proxy_pass http://bytebase.example.com;
            proxy_http_version 1.1;
            # Enables WebSocket which is required for SQL Editor autocomplete
            proxy_set_header Upgrade $http_upgrade;
            proxy_set_header Connection $connection_upgrade;
        }
        ...
    }
}
```

## Run query

Click the `Run` button or use the shortcut key `(⌘ + Enter)` to run your queries in the SQL Editor.

If you have multiple SQL queries separated by semicolons, SQL Editor will only run the first query for now.

### Max returned row count

SQL Editor can return at most **100,000 rows**.

<img src="https://mintcdn.com/dbx/oPldGQC4HFcCc-EY/content/docs/sql-editor/query-row-limit.webp?fit=max&auto=format&n=oPldGQC4HFcCc-EY&q=85&s=e882ac983ebceddf3d833a928bf9b68b" alt="Query Row Limit" width="704" height="473" data-path="content/docs/sql-editor/query-row-limit.webp" />

### Max returned result size

The default query result size is **100 MB**. You can change it under the Workspace settings.

<img src="https://mintcdn.com/dbx/oPldGQC4HFcCc-EY/content/docs/sql-editor/query-result-size-limit.webp?fit=max&auto=format&n=oPldGQC4HFcCc-EY&q=85&s=9762ba98ad89f4b0e98815ee49053ef5" alt="Query Result Size Limit" width="957" height="551" data-path="content/docs/sql-editor/query-result-size-limit.webp" />

## Export data

<Info>
  **Export re-runs your SQL statement against the database** — it does not download the result set currently displayed in the tab. If the underlying data changed between the time you ran the query and the time you clicked **Export**, the exported rows will reflect the later state. To capture a specific point-in-time result set, copy the rows from the result panel or re-run the query immediately before exporting.

  The re-execution goes through the same row limit, data-source selection, and [masking policy](/sql-editor/mask-data) as the original query, so exported columns are masked if the policy is enforced.
</Info>

If you have been granted export access, you can directly export query results in various formats.

<img src="https://mintcdn.com/dbx/oPldGQC4HFcCc-EY/content/docs/sql-editor/export-data.webp?fit=max&auto=format&n=oPldGQC4HFcCc-EY&q=85&s=22ea72cbac67b0439a9134a378821f95" alt="Export Data" width="978" height="693" data-path="content/docs/sql-editor/export-data.webp" />

Otherwise, you can request the exported data

<img src="https://mintcdn.com/dbx/oPldGQC4HFcCc-EY/content/docs/sql-editor/export-request1.webp?fit=max&auto=format&n=oPldGQC4HFcCc-EY&q=85&s=eb2fb3b8ca07a3c39d3c9c63f5bcf268" alt="Request Export" width="1019" height="741" data-path="content/docs/sql-editor/export-request1.webp" />

<img src="https://mintcdn.com/dbx/oPldGQC4HFcCc-EY/content/docs/sql-editor/export-request2.webp?fit=max&auto=format&n=oPldGQC4HFcCc-EY&q=85&s=ab65b1fb6aaf163fe371d241e55d7baf" alt="Request Export" width="1006" height="847" data-path="content/docs/sql-editor/export-request2.webp" />

## EXPLAIN query

<img src="https://mintcdn.com/dbx/yhR4_AKNF_MEUOA1/content/docs/sql-editor/explain-query.webp?fit=max&auto=format&n=yhR4_AKNF_MEUOA1&q=85&s=a8f7d0f2239a4c53361bac3b47eca38c" alt="Explain Query" width="722" height="422" data-path="content/docs/sql-editor/explain-query.webp" />

SQL Editor provides an `Explain Query` action to run EXPLAIN on the selected query. You can access it from right click or use the shortcut key `(⌘ + E)` instead of prepending EXPLAIN manually.

Bytebase provides visual plan representations for different databases:

* **PostgreSQL**: Embeds [PEV2](https://github.com/dalibo/pev2) to visualize the execution plan

  <img src="https://mintcdn.com/dbx/yhR4_AKNF_MEUOA1/content/docs/sql-editor/explain-postgres-1.webp?fit=max&auto=format&n=yhR4_AKNF_MEUOA1&q=85&s=c28e2143b68abc1eb1e6cc3689622b8b" alt="visualize-plan" width="1273" height="800" data-path="content/docs/sql-editor/explain-postgres-1.webp" />

  <img src="https://mintcdn.com/dbx/yhR4_AKNF_MEUOA1/content/docs/sql-editor/explain-postgres-2.webp?fit=max&auto=format&n=yhR4_AKNF_MEUOA1&q=85&s=113b6604dc2903ebe782f47cd1de3639" alt="visualize-plan" width="1274" height="802" data-path="content/docs/sql-editor/explain-postgres-2.webp" />

* **SQL Server**: Provides native graphical execution plan visualization

  <img src="https://mintcdn.com/dbx/OA9iSh6nWmJdEdly/content/docs/sql-editor/explain-mssql-1.webp?fit=max&auto=format&n=OA9iSh6nWmJdEdly&q=85&s=fb56da600e234fcfcc3abbd55e1ba785" alt="mssql-visualize-plan" width="761" height="658" data-path="content/docs/sql-editor/explain-mssql-1.webp" />

  <img src="https://mintcdn.com/dbx/OA9iSh6nWmJdEdly/content/docs/sql-editor/explain-mssql-2.webp?fit=max&auto=format&n=OA9iSh6nWmJdEdly&q=85&s=bd83112b469ac85cd47100646124d983" alt="mssql-visualize-plan" width="781" height="110" data-path="content/docs/sql-editor/explain-mssql-2.webp" />

## Batch mode

You can batch query many databases having the same schema:

<img src="https://mintcdn.com/dbx/rjEeWG57hKfio7SS/content/docs/sql-editor/bb-batch-query-setting.webp?fit=max&auto=format&n=rjEeWG57hKfio7SS&q=85&s=0239dd5c1665a148b30b0030bbf7e504" alt="batch-query-setting" width="2354" height="1084" data-path="content/docs/sql-editor/bb-batch-query-setting.webp" />

For each database, the query result will show up in its own tab:

<img src="https://mintcdn.com/dbx/rjEeWG57hKfio7SS/content/docs/sql-editor/bb-batch-query-results.webp?fit=max&auto=format&n=rjEeWG57hKfio7SS&q=85&s=b06a700495cc023dd7d4fecc5b073ddd" alt="batch-query-result1" width="2546" height="1190" data-path="content/docs/sql-editor/bb-batch-query-results.webp" />
