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

> ## Agent Instructions
> PawSQL 是一个产品：Cloud 是公网部署形态，Engine / Optimizer / Auditor / Advisor / Patroller 是同一产品的组件与交付形态，不是彼此独立的产品。 / PawSQL is a single product: Cloud is the public deployment form, while Engine / Optimizer / Auditor / Advisor / Patroller are components and delivery forms of the same product, not separate products.
> 术语以站内术语表为准：SQL 审核对应英文 SQL Review，查询重写对应 Query Rewrite，索引推荐对应 Index Recommendation；英文内容统一用 Review，不用 Audit。 / Use the site glossary for terminology: 审核 is SQL Review, 重写 is Query Rewrite, 索引推荐 is Index Recommendation; English content uses Review, never Audit.
> 引用能力范围或版本支持时以对应页面为准；标注 unknown、或 status 非 published 的内容表示尚未经产品核实，不应作为事实引用。 / Cite capability scope and version support from the corresponding page; content marked unknown, or with a status other than published, is not yet product-verified and must not be cited as fact.

# Optimize SQL in Visual Studio Code

> Install and configure PawSQL Client for VS Code to optimize SQL within source files and SQL scripts.

PawSQL Client for VS Code brings SQL review, query rewrite, index recommendation, and performance validation into Visual Studio Code. It is designed for quick analysis of a current statement in a polyglot repository or standalone SQL file.

## Goal

Install and configure PawSQL Client for VS Code to optimize SQL within source files and SQL scripts.

## Prerequisites

A compatible Visual Studio Code installation and access to the Visual Studio Code Marketplace (or an offline extension package supplied by PawSQL or an approved internal repository).

## Install the extension

Install from the Visual Studio Code Marketplace; see [Install IDE Extensions](/en/user-guide/installation/ide-plugins) for steps. After installation, open a file containing SQL and confirm that a PawSQL optimization action appears near the detected statement.

In a restricted network, use only an offline extension package supplied by PawSQL or an approved internal software repository.

## Connect to PawSQL

<Steps>
  <Step title="Open PawSQL configuration">
    Use the extension settings or command palette to open PawSQL Client configuration.
  </Step>

  <Step title="Set the endpoint">
    Enter the complete PawSQL Cloud or PawSQL Server URL.
  </Step>

  <Step title="Authenticate">
    Sign in or provide the credential required by your deployment. Keep passwords and tokens out of project files.
  </Step>

  <Step title="Choose a default workspace">
    Select a workspace that matches the target database engine, version, and schema.
  </Step>
</Steps>

## Optimize a statement

<Steps>
  <Step title="Locate complete SQL">
    Open the source or SQL file and make sure the extension recognizes the full statement boundary.
  </Step>

  <Step title="Use the default workspace">
    Select **Optimize** from the SQL prompt to run the task with the configured default workspace.
  </Step>

  <Step title="Choose another workspace">
    Select **Optimize...** and choose the workspace for this task.
  </Step>

  <Step title="Open the result">
    Review the PawSQL findings, rewrite candidates, index recommendations, and performance evidence.
  </Step>
</Steps>

<Frame caption="Optimize action next to a SQL statement">
  <img src="https://mintlify.s3.us-west-1.amazonaws.com/pawsql/en/user-guide/dev-tools//images/tools/vscode-optimize.png" alt="Optimize" />
</Frame>

<Tip>
  If one repository targets several engines or environments, do not rely on one default workspace for every statement. Use **Optimize...** to select the context that matches the current SQL.
</Tip>

## Read optimization results

The presentation may change between extension releases. Use this review order:

1. Verify the original SQL and detected database dialect.
2. Confirm the workspace and object resolution.
3. Read findings, severity, and affected fragments.
4. Evaluate rewritten SQL and the optimization rationale.
5. Inspect candidate indexes and their relationship to existing indexes.
6. Review plan or performance comparisons when validation is enabled.

## Verification

Confirm the extension works by running an optimization and checking that the original SQL, detected dialect, workspace, findings, rewrite candidates, index recommendations, and any validation evidence are returned.

## Apply a rewrite or index

Extension output is an optimization candidate, not a deployment instruction. Before applying it:

* verify query results and business semantics;
* test parameter types, null handling, and boundary values;
* confirm target-version syntax support;
* account for index write and storage cost;
* validate plans under representative conditions;
* follow code review and database change approval.

<Warning>
  When validation requires database access or SQL execution, confirm the account permissions, target environment, and statement safety first. Do not use an unreviewed data-changing statement for the initial connection test.
</Warning>

## Troubleshooting

| Symptom                                      | Check first                                                      |
| -------------------------------------------- | ---------------------------------------------------------------- |
| Extension is not listed                      | VS Code version, Marketplace access, proxy, and corporate policy |
| No Optimize action appears                   | File language mode, SQL completeness, and extension status       |
| PawSQL is unreachable                        | Endpoint, TLS trust, proxy, authentication, and service health   |
| No workspace is available                    | Project membership and workspace permissions                     |
| Tables or indexes are unresolved             | Workspace, engine version, schema, and metadata freshness        |
| Recommendations target the wrong environment | Default workspace or the workspace selected for this task        |

## Related documentation

<CardGroup cols={2}>
  <Card title="Workspaces and Database Context" href="/en/user-guide/workspaces" />

  <Card title="Input SQL to Optimize" href="/en/user-guide/optimization/create-workload" />

  <Card title="Read Optimization Results" href="/en/user-guide/optimization/explain-output" />

  <Card title="Evaluate and Apply Suggestions" href="/en/user-guide/optimization/apply-suggestions" />
</CardGroup>
