Skip to content

lake: add materialized view and update ALTER VIEW - #23711

Open
lilin90 wants to merge 1 commit into
pingcap:release-8.5from
lilin90:lake-0830
Open

lake: add materialized view and update ALTER VIEW#23711
lilin90 wants to merge 1 commit into
pingcap:release-8.5from
lilin90:lake-0830

Conversation

@lilin90

@lilin90 lilin90 commented Sep 2, 2026

Copy link
Copy Markdown
Member

What is changed, added or deleted? (Required)

Introduce a new Materialized View page covering concepts, limitations, create/refresh/alter/show/drop syntax, and access control. Update the View TOC and overview to include materialized views, and clarify that ALTER VIEW in TiDB Cloud Lake is for tag management only (with guidance to use CREATE OR REPLACE VIEW for definition changes).

Which TiDB version(s) do your changes apply to? (Required)

Tips for choosing the affected version(s):

By default, CHOOSE MASTER ONLY so your changes will be applied to the next TiDB major or minor releases. If your PR involves a product feature behavior change or a compatibility change, CHOOSE THE AFFECTED RELEASE BRANCH(ES) AND MASTER.

For details, see tips for choosing the affected versions.

  • master (the latest development version)
  • v9.0 (TiDB 9.0 versions)
  • v8.5 (TiDB 8.5 versions)
  • v8.1 (TiDB 8.1 versions)
  • v7.5 (TiDB 7.5 versions)
  • v7.1 (TiDB 7.1 versions)
  • v6.5 (TiDB 6.5 versions)

What is the related PR or file link(s)?

  • This PR is translated from:
  • Other reference link(s):

AI agent involvement

  • The changes in this PR were primarily made by an AI agent on behalf of the PR author.

Do your changes match any of the following descriptions?

  • Delete files
  • Change aliases
  • Need modification after applied to another branch
  • Might cause conflicts after applied to another branch

Summary by CodeRabbit

  • New Features

    • Added documentation for materialized views, including creation, refresh, maintenance, limitations, and access requirements.
    • Added materialized views to the view management documentation and table of contents.
  • Documentation

    • Clarified that modifying a view with ALTER VIEW ... AS SELECT is unsupported; use CREATE OR REPLACE VIEW instead.
    • Updated ALTER VIEW documentation to focus on assigning or removing tags.

Introduce a new Materialized View page covering concepts, limitations, create/refresh/alter/show/drop syntax, and access control. Update the View TOC and overview to include materialized views, and clarify that `ALTER VIEW` in TiDB Cloud Lake is for tag management only (with guidance to use `CREATE OR REPLACE VIEW` for definition changes).
@lilin90 lilin90 self-assigned this Sep 2, 2026
@lilin90 lilin90 added translation/no-need No need to translate this PR. lake Related to TiDB Cloud Lake docs. labels Sep 2, 2026
@ti-chi-bot

ti-chi-bot Bot commented Sep 2, 2026

Copy link
Copy Markdown

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by:
Once this PR has been reviewed and has the lgtm label, please ask for approval from lilin90. For more information see the Code Review Process.
Please ensure that each of them provides their approval before proceeding.

The full list of commands accepted by this bot can be found here.

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@ti-chi-bot ti-chi-bot Bot added the size/L Denotes a PR that changes 100-499 lines, ignoring generated files. label Sep 2, 2026
@lilin90
lilin90 requested a review from awxxxxxx September 2, 2026 09:20
@coderabbitai

coderabbitai Bot commented Sep 2, 2026

Copy link
Copy Markdown

Review Change Stack

📝 Walkthrough

Walkthrough

The documentation adds a materialized-view reference, updates view navigation, clarifies ALTER VIEW behavior, and directs query replacement to CREATE OR REPLACE VIEW.

Changes

View documentation

Layer / File(s) Summary
Materialized view reference
tidb-cloud-lake/sql/materialized-view.md
Documents materialized-view definitions, creation, refresh, maintenance, inspection, removal, limitations, and access control.
View reference navigation
TOC-tidb-cloud-lake.md, tidb-cloud-lake/sql/ddl-view-overview.md
Adds materialized views to the navigation and view management table. The table describes physical storage and updates the ALTER VIEW behavior.
ALTER VIEW documentation
tidb-cloud-lake/sql/alter-view.md
Documents tag assignment and removal. It removes unsupported query replacement syntax and directs users to CREATE OR REPLACE VIEW.

Estimated code review effort: 2 (Simple) | ~10 minutes

Merge Risk: 🟡 Moderate · up to 0c138

The documentation currently misstates ALTER VIEW capabilities and leaves materialized-view refresh and automatic-maintenance behavior contradictory, which could lead users to apply unsupported SQL or misunderstand result freshness. Merge should wait until these behavior descriptions are corrected.

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description check ✅ Passed The description includes the required change summary and affected TiDB version. Optional reference links and conditional checklist items are left blank, but the description is otherwise complete and r…
Title check ✅ Passed The title clearly identifies the two main changes: adding materialized view documentation and updating ALTER VIEW documentation for TiDB Cloud Lake.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check. Docstring coverage is scoped to functions touched by this diff. Analyzed 0 functions across 0…
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Full details: Description check

Explanation

The description includes the required change summary and affected TiDB version. Optional reference links and conditional checklist items are left blank, but the description is otherwise complete and relevant.

Full details: Docstring Coverage

Explanation

No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check. Docstring coverage is scoped to functions touched by this diff. Analyzed 0 functions across 0 files. (4 skipped: 4 unsupported.)

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2


ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Team

Run ID: 5c3c0967-ad05-465c-a23a-a7363490f886

📥 Commits

Reviewing files that changed from the base of the PR and between 0acbc96 and 0c13869.

📒 Files selected for processing (4)
  • TOC-tidb-cloud-lake.md
  • tidb-cloud-lake/sql/alter-view.md
  • tidb-cloud-lake/sql/ddl-view-overview.md
  • tidb-cloud-lake/sql/materialized-view.md

Included review availability: Your plan provides up to 4 included reviews per hour; 3 remain after this review.

```
> **Note:**
>
> `ALTER VIEW ... AS ...` is not supported. To change a view's query or output columns, use [CREATE OR REPLACE VIEW](/tidb-cloud-lake/sql/create-view.md) instead.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🎯 Functional Correctness | 🟠 Major | 🏗️ Heavy lift

🔎 Supported by static analysis

🏁 Script executed:

#!/bin/bash
set -eu
printf '%s\n' '--- applicable conventions ---'
find /tmp/coderabbit-repo-knowledge/pingcap-docs-9c73f70c -maxdepth 2 -type f \( -path '*/coding-guidelines/*' -o -path '*/conventions/*' -o -path '*/learnings/*' -o -path '*/architecture/*' \) -print 2>/dev/null | sort
printf '%s\n' '--- repository files ---'
git ls-files 'tidb-cloud-lake/sql/alter-view.md' '*privilege*' '*view*.md' | head -80
printf '%s\n' '--- target document ---'
cat -n tidb-cloud-lake/sql/alter-view.md
printf '%s\n' '--- diff summary and target diff ---'
git diff --stat
git diff -- tidb-cloud-lake/sql/alter-view.md

Repository: pingcap/docs

Length of output: 4868


🏁 Script executed:

#!/bin/bash
set -eu
printf '%s\n' '--- repository review conventions ---'
cat /tmp/coderabbit-repo-knowledge/pingcap-docs-9c73f70c/conventions/repo-wide.md
printf '%s\n' '--- privilege references to ALTER VIEW ---'
rg -n -C 5 'ALTER VIEW|alter an existing view|another query' tidb-cloud-lake/guides/privileges.md tidb-cloud-lake/lake-overview.md tidb-cloud-lake/sql/*.md
printf '%s\n' '--- related view documents ---'
cat -n tidb-cloud-lake/sql/create-view.md | sed -n '1,180p'
cat -n tidb-cloud-lake/sql/ddl-view-overview.md | sed -n '1,160p'

Repository: pingcap/docs

Length of output: 12078


🌐 Web query:

TiDB Cloud Lake v8.5 ALTER VIEW AS SELECT support CREATE OR REPLACE VIEW privileges

💡 Result:

In TiDB Cloud Lake v8.5, the support for ALTER VIEW and CREATE OR REPLACE VIEW differs significantly from the standard TiDB (MySQL-compatible) product. For TiDB Cloud Lake v8.5: - ALTER VIEW: Full support is provided for the ALTER VIEW ... AS SELECT ... statement to modify an existing view [1][2]. - CREATE OR REPLACE VIEW: Support for the OR REPLACE syntax is explicitly documented, allowing you to overwrite an existing view with the same name [3]. - Privilege Requirements: To access a view in TiDB Cloud Lake, users only require the SELECT privilege on the view itself; separate permissions on the underlying base tables are not required [3]. In contrast, standard TiDB (e.g., v8.1, v8.5) does not support the ALTER VIEW statement [4][5]. In standard TiDB, you must either drop and recreate the view or use CREATE OR REPLACE VIEW to update it [4][6]. Standard TiDB also requires specific privileges, such as CREATE VIEW (and potentially SUPER depending on the situation), to manage views [7][8]. Always ensure you are consulting the documentation specific to the "TiDB Cloud Lake" product line if you are utilizing that architecture, as its SQL syntax and behavioral characteristics may diverge from the standard TiDB database product [1][2][3].

Citations:


🏁 Script executed:

#!/bin/bash
set -eu
for url in \
  'https://docs.pingcap.com/tidbcloudlake/alter-view/' \
  'https://docs.pingcap.com/tidbcloudlake/ddl-view-overview/' \
  'https://docs.pingcap.com/tidbcloudlake/guides/privileges/'; do
  printf '\n--- %s ---\n' "$url"
  curl -L --max-time 15 -fsS "$url" |
    sed 's/<[^>]*>/ /g; s/&amp;/\&/g; s/&quot;/"/g; s/&`#39`;/'"'"'/g' |
    tr -s '[:space:]' ' ' |
    grep -o -E '.{0,220}(ALTER VIEW|CREATE OR REPLACE VIEW|another query|view privilege).{0,320}' || true
done

Repository: pingcap/docs

Length of output: 4095


Restore ALTER VIEW ... AS SELECT ... support.

The TiDB Cloud Lake ALTER VIEW contract documents this syntax and examples. Line 12 contradicts that contract and removes supported query alteration from the page. Restore the syntax and examples instead of documenting it as unsupported.

Sources: Path instructions, MCP tools

- A definition must be a simple `SELECT ... FROM ... [WHERE ...] [GROUP BY ...]` query over exactly one base table. Joins, subqueries, set operations, and non-deterministic functions are not supported.
- Aggregations are supported only for `sum`, `min`, `max`, `avg`, `count`, and `approx_count_distinct`. `DISTINCT`, `FILTER`, window, and ordered aggregate forms are not supported.
- The source must be a persistent FUSE base table in the `default` catalog. A materialized view cannot use another view or a different table engine as its source.
- Materialized views are read-only. Use `REFRESH MATERIALIZED VIEW` to maintain their contents; `INSERT`, `UPDATE`, `DELETE`, `TRUNCATE`, and ordinary `ALTER TABLE` operations are not supported.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🗄️ Data Integrity & Integration | 🟠 Major | ⚡ Quick win

Separate automatic maintenance from explicit refresh.

The capability table at tidb-cloud-lake/guides/editions.md:64 advertises automatic maintenance of materialized-view results. tidb-cloud-lake/sql/ddl-view-overview.md:17 also says that materialized views are maintained. This bullet instead says users must use REFRESH MATERIALIZED VIEW to maintain contents. Clarify which changes are automatic and which require explicit refresh. (docs.pingcap.com)

Committable replacement
- Materialized views are read-only. Use `REFRESH MATERIALIZED VIEW` to maintain their contents; `INSERT`, `UPDATE`, `DELETE`, `TRUNCATE`, and ordinary `ALTER TABLE` operations are not supported.
+ Materialized views are read-only. {{{ .lake }}} automatically maintains their results for supported source changes. Use `REFRESH MATERIALIZED VIEW` to materialize the initial data and to rebuild the result when incremental maintenance is invalidated; `INSERT`, `UPDATE`, `DELETE`, `TRUNCATE`, and ordinary `ALTER TABLE` operations on the materialized view are not supported.

As per path instructions, this Markdown finding includes a committable replacement because the fix is a safe contiguous change.

📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
- Materialized views are read-only. Use `REFRESH MATERIALIZED VIEW` to maintain their contents; `INSERT`, `UPDATE`, `DELETE`, `TRUNCATE`, and ordinary `ALTER TABLE` operations are not supported.
Materialized views are read-only. {{{ .lake }}} automatically maintains their results for supported source changes. Use `REFRESH MATERIALIZED VIEW` to materialize the initial data and to rebuild the result when incremental maintenance is invalidated; `INSERT`, `UPDATE`, `DELETE`, `TRUNCATE`, and ordinary `ALTER TABLE` operations on the materialized view are not supported.

Sources: Path instructions, MCP tools

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

lake Related to TiDB Cloud Lake docs. size/L Denotes a PR that changes 100-499 lines, ignoring generated files. translation/no-need No need to translate this PR.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant