Skip to content

*: Support TIDB_VIEWS, TIDB_MLOGS and TIDB_TABLE_MVIEW_DEPENDENCIES in INFORMATION_SCHEMA for materialized view#68839

Open
xzhangxian1008 wants to merge 19 commits into
pingcap:feature/release-8.5-materialized-view-2603from
xzhangxian1008:info-tb
Open

*: Support TIDB_VIEWS, TIDB_MLOGS and TIDB_TABLE_MVIEW_DEPENDENCIES in INFORMATION_SCHEMA for materialized view#68839
xzhangxian1008 wants to merge 19 commits into
pingcap:feature/release-8.5-materialized-view-2603from
xzhangxian1008:info-tb

Conversation

@xzhangxian1008
Copy link
Copy Markdown
Contributor

@xzhangxian1008 xzhangxian1008 commented Jun 1, 2026

What problem does this PR solve?

Issue Number: close #68838

Problem Summary:

What changed and how does it work?

Check List

Tests

  • Unit test
  • Integration test
  • Manual test (add detailed scripts or steps below)
  • No need to test
    • I checked and no code files have been changed.

Side effects

  • Performance regression: Consumes more CPU
  • Performance regression: Consumes more Memory
  • Breaking backward compatibility

Documentation

  • Affects user behaviors
  • Contains syntax changes
  • Contains variable changes
  • Contains experimental features
  • Changes MySQL compatibility

Release note

Please refer to Release Notes Language Style Guide to write a quality release note.

Support TIDB_VIEWS, TIDB_MLOGS and TIDB_TABLE_MVIEW_DEPENDENCIES in INFORMATION_SCHEMA for materialized view

Summary by CodeRabbit

  • New Features

    • Added three information_schema tables for materialized view metadata: tidb_mviews, tidb_mlogs, tidb_table_mview_dependencies.
    • Improved query filtering (including LIKE/IN patterns) and timezone-aware modification timestamps for materialized view records.
  • Tests

    • Added extensive unit and integration tests covering materialized views, logs, dependencies, filtering, and timestamp behavior.

@ti-chi-bot ti-chi-bot Bot added do-not-merge/invalid-title release-note Denotes a PR that will be considered when it comes time to generate release notes. labels Jun 1, 2026
@ti-chi-bot
Copy link
Copy Markdown

ti-chi-bot Bot commented Jun 1, 2026

[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 assign gmhdbjd, terry1purcell for approval. 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 sig/planner SIG: Planner size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files. labels Jun 1, 2026
@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Jun 1, 2026

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: 46f925ba-5769-46ca-836a-9c3d99035f67

📥 Commits

Reviewing files that changed from the base of the PR and between fa0790d and c26c43b.

📒 Files selected for processing (1)
  • pkg/executor/test/ddl/materialized_view_ddl_test.go
🚧 Files skipped from review as they are similar to previous changes (1)
  • pkg/executor/test/ddl/materialized_view_ddl_test.go

📝 Walkthrough

Walkthrough

Adds three TiDB-specific INFORMATION_SCHEMA tables for materialized views, implements predicate extractors, executor data loaders with privilege/timezone handling, wires planner/builder, and provides unit and integration tests.

Changes

Materialized View INFORMATION_SCHEMA Support

Layer / File(s) Summary
Schema definitions for new INFORMATION_SCHEMA tables
pkg/infoschema/tables.go
Adds exported constants TableTiDBMViews, TableTiDBMLogs, TableTiDBTableMViewDependencies, assigns table IDs, and declares column schemas for all three tables.
Predicate extractors for query optimization
pkg/planner/core/memtable_infoschema_extractor.go
Adds column-name constants and three extractors: InfoSchemaTiDBMViewsExtractor, InfoSchemaTiDBMLogsExtractor (with base-table-aware listing/dedup), and InfoSchemaTiDBTableMViewDependenciesExtractor (with mlog/mview listing helpers and Filter implementations).
Planner and builder wiring
pkg/planner/core/logical_plan_builder.go, pkg/executor/builder.go, pkg/executor/BUILD.bazel
Wires new extractors into the planner, routes the three table names through memtable retriever in the builder, and adds //pkg/privilege to the executor_test deps.
Data population in executor
pkg/executor/infoschema_reader.go
Implements setDataFromTiDBMViews, setDataFromTiDBMLogs, and setDataFromTiDBTableMViewDependencies with predicate-aware candidate listing, privilege checks, dependency resolution, purge-schedule handling, and timezone-aware MVIEW_MODIFY_TIME.
Unit tests for extractors and data population
pkg/executor/infoschema_reader_internal_test.go, pkg/planner/core/operator/logicalop/logicalop_test/logical_mem_table_predicate_extractor_test.go
Adds extensive unit tests covering extractor predicate parsing, request skipping, error propagation, privilege auditing, and timezone-sensitive timestamp assertions.
Integration and executor-level tests
pkg/executor/test/ddl/materialized_view_ddl_test.go, tests/integrationtest/t/executor/infoschema_mv.test, tests/integrationtest/r/executor/infoschema_mv.result
Adds end-to-end SQL tests exercising creation of materialized view logs/views, REFRESH FAST scheduling, purge configurations, and validates results across many WHERE/pattern/IN-list predicate combinations and dependency queries.

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~60 minutes

Suggested labels

ok-to-test

Suggested reviewers

  • wjhuang2016
  • windtalker
  • gengliqi
  • wshwsh12

Poem

🐰 Three small tables hop into view,
Columns and predicates all lined in a queue,
Extractors sniff patterns, rows bloom on demand,
Privileges checked by a careful paw and hand,
Metadata sings—fresh, tidy, and true.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 10.34% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately describes the main feature: adding support for three INFORMATION_SCHEMA tables for materialized views.
Description check ✅ Passed The description includes issue reference, test checkboxes, and release notes but lacks detailed explanation of changes and how they work.
Linked Issues check ✅ Passed The PR implements all three required INFORMATION_SCHEMA tables (TIDB_VIEWS, TIDB_MLOGS, TIDB_TABLE_MVIEW_DEPENDENCIES) with proper data retrieval, privilege checks, and comprehensive tests.
Out of Scope Changes check ✅ Passed All changes directly support the feature: infoschema definitions, executor data retrieval, planner extractors, and comprehensive unit/integration tests. One Bazel test sharding update is an incidental optimization.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

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

Warning

There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure.

🔧 golangci-lint (2.12.2)

Error: can't load config: unsupported version of the configuration: "" See https://golangci-lint.run/docs/product/migration-guide for migration instructions
The command is terminated due to an error: can't load config: unsupported version of the configuration: "" See https://golangci-lint.run/docs/product/migration-guide for migration instructions


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 and usage tips.

@tiprow
Copy link
Copy Markdown

tiprow Bot commented Jun 1, 2026

Hi @xzhangxian1008. Thanks for your PR.

PRs from untrusted users cannot be marked as trusted with /ok-to-test in this repo meaning untrusted PR authors can never trigger tests themselves. Collaborators can still trigger tests on the PR using /test all.

I understand the commands that are listed here.

Details

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository.

@xzhangxian1008 xzhangxian1008 changed the title Support TIDB_VIEWS, TIDB_MLOGS and TIDB_TABLE_MVIEW_DEPENDENCIES in INFORMATION_SCHEMA for materialized view *: Support TIDB_VIEWS, TIDB_MLOGS and TIDB_TABLE_MVIEW_DEPENDENCIES in INFORMATION_SCHEMA for materialized view Jun 1, 2026
Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 3

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@pkg/infoschema/tables.go`:
- Line 760: Change the new ID columns from VARCHAR to a numeric LONG type:
update the column definition for BASE_TABLE_ID (and the other new ID column
added nearby) to use mysql.TypeLonglong with size 20 and keep the
mysql.NotNullFlag (match the existing TIDB_MVIEWS.MVIEW_ID type/semantics);
ensure both places that currently set tp: mysql.TypeVarchar are changed to tp:
mysql.TypeLonglong and adjust size/flags accordingly so the INFORMATION_SCHEMA
ID fields are numeric and consistent.

In `@tests/integrationtest/t/executor/infoschema_mv.test`:
- Around line 45-51: The test currently snapshots raw MVIEW_MODIFY_TIME (queries
selecting MVIEW_MODIFY_TIME from information_schema.tidb_mviews), which bakes
wall-clock timestamps into infoschema_mv.result; update the test in
tests/integrationtest/t/infoschema_mv.test to stop capturing the raw
timestamp—either remove MVIEW_MODIFY_TIME from the SELECT projections or replace
that projection with a stable predicate/assertion (e.g., assert
MVIEW_MODIFY_TIME IS NOT NULL or use a deterministic flag column) in the queries
that reference MVIEW_MODIFY_TIME so the golden output is stable across
regenerations.
- Around line 13-15: The information_schema queries in
tests/integrationtest/t/executor/infoschema_mv.test are reading global state
(e.g., mv_t, mv_t1, mvv_t1, $mlog$t) which makes the golden output
order-dependent; modify the two queries that currently select from
information_schema.tidb_mviews and information_schema.tables to filter to the
test fixtures (for example by TABLE_SCHEMA = '<test_schema>' or by MVIEW_NAME IN
('mv_t','mv_t1','mvv_t1') / TABLE_NAME LIKE '$mlog$t%') so only objects created
by this test are counted, and add teardown steps at the end of the test to drop
mv_t, mv_t1, mvv_t1 and any $mlog$t artifacts (or create/use a dedicated schema
and drop it) so the test result is deterministic and stable.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: 63a4fe24-61fc-46f6-a1dc-58bca52fcae4

📥 Commits

Reviewing files that changed from the base of the PR and between 7a81553 and fa0790d.

📒 Files selected for processing (12)
  • pkg/executor/BUILD.bazel
  • pkg/executor/builder.go
  • pkg/executor/infoschema_reader.go
  • pkg/executor/infoschema_reader_internal_test.go
  • pkg/executor/test/ddl/materialized_view_ddl_test.go
  • pkg/infoschema/tables.go
  • pkg/planner/core/logical_plan_builder.go
  • pkg/planner/core/memtable_infoschema_extractor.go
  • pkg/planner/core/operator/logicalop/logicalop_test/BUILD.bazel
  • pkg/planner/core/operator/logicalop/logicalop_test/logical_mem_table_predicate_extractor_test.go
  • tests/integrationtest/r/executor/infoschema_mv.result
  • tests/integrationtest/t/executor/infoschema_mv.test

Comment thread pkg/infoschema/tables.go
{name: "MLOG_COLUMNS", tp: mysql.TypeLongBlob, size: types.UnspecifiedLength, flag: mysql.NotNullFlag},
{name: "BASE_TABLE_CATALOG", tp: mysql.TypeVarchar, size: 512, flag: mysql.NotNullFlag},
{name: "BASE_TABLE_SCHEMA", tp: mysql.TypeVarchar, size: 64, flag: mysql.NotNullFlag},
{name: "BASE_TABLE_ID", tp: mysql.TypeVarchar, size: 64, flag: mysql.NotNullFlag},
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟠 Major | ⚡ Quick win

Use numeric types for the new ID metadata columns.

Line 760 and Line 776 publish table IDs as VARCHAR, but the rest of this feature treats them as numeric identifiers (TIDB_MVIEWS.MVIEW_ID is already LONG, and the new extractors resolve these predicates via parseIDs). Exposing them as strings changes comparison/order semantics for the new INFORMATION_SCHEMA tables and makes the schemas inconsistent with the corresponding ID fields.

Proposed fix
-	{name: "BASE_TABLE_ID", tp: mysql.TypeVarchar, size: 64, flag: mysql.NotNullFlag},
+	{name: "BASE_TABLE_ID", tp: mysql.TypeLonglong, size: 21, flag: mysql.NotNullFlag},
...
-	{name: "MVIEW_ID", tp: mysql.TypeVarchar, size: 64, flag: mysql.NotNullFlag},
+	{name: "MVIEW_ID", tp: mysql.TypeLonglong, size: 21, flag: mysql.NotNullFlag},

Also applies to: 776-776

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@pkg/infoschema/tables.go` at line 760, Change the new ID columns from VARCHAR
to a numeric LONG type: update the column definition for BASE_TABLE_ID (and the
other new ID column added nearby) to use mysql.TypeLonglong with size 20 and
keep the mysql.NotNullFlag (match the existing TIDB_MVIEWS.MVIEW_ID
type/semantics); ensure both places that currently set tp: mysql.TypeVarchar are
changed to tp: mysql.TypeLonglong and adjust size/flags accordingly so the
INFORMATION_SCHEMA ID fields are numeric and consistent.

Comment on lines +13 to +15
select count(*) from information_schema.tidb_mviews;
select TABLE_SCHEMA, MVIEW_NAME from information_schema.tidb_mviews;

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟠 Major | ⚡ Quick win

Scope these assertions to this file’s fixtures.

These queries read global INFORMATION_SCHEMA state, and this file never drops mv_t/mv_t1/mvv_t1 or $mlog$t. That makes the expected results suite-order dependent; Line 71 already has to weaken to count(*) >= 2 to tolerate leaked state. Filter by the objects created here (or use a dedicated schema) and clean them up at the end so the golden file stays stable. As per coding guidelines, tests/integrationtest/t/**: Integration test files changed: record and verify regenerated result correctness.

Also applies to: 39-40, 71-71

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@tests/integrationtest/t/executor/infoschema_mv.test` around lines 13 - 15,
The information_schema queries in
tests/integrationtest/t/executor/infoschema_mv.test are reading global state
(e.g., mv_t, mv_t1, mvv_t1, $mlog$t) which makes the golden output
order-dependent; modify the two queries that currently select from
information_schema.tidb_mviews and information_schema.tables to filter to the
test fixtures (for example by TABLE_SCHEMA = '<test_schema>' or by MVIEW_NAME IN
('mv_t','mv_t1','mvv_t1') / TABLE_NAME LIKE '$mlog$t%') so only objects created
by this test are counted, and add teardown steps at the end of the test to drop
mv_t, mv_t1, mvv_t1 and any $mlog$t artifacts (or create/use a dedicated schema
and drop it) so the test result is deterministic and stable.

Comment on lines +45 to +51
select TABLE_SCHEMA, MVIEW_NAME, MVIEW_MODIFY_TIME, REFRESH_METHOD from information_schema.tidb_mviews where MVIEW_NAME = "mv_t" or MVIEW_NAME like "%mvv%" order by 1, 2, 3;
select TABLE_SCHEMA, MVIEW_NAME, REFRESH_METHOD from information_schema.tidb_mviews where MVIEW_NAME in ("mv_t", "mv", "mv_t1") order by 1, 2, 3;
select TABLE_SCHEMA, MVIEW_NAME, REFRESH_METHOD from information_schema.tidb_mviews where MVIEW_NAME not in ("mv", "mv_t1") order by 1, 2, 3;
select TABLE_SCHEMA, MVIEW_NAME, REFRESH_METHOD from information_schema.tidb_mviews where TABLE_SCHEMA = "test" and MVIEW_NAME like "%mvv%" order by 1, 2, 3;
select TABLE_SCHEMA, MVIEW_NAME, REFRESH_METHOD from information_schema.tidb_mviews where REFRESH_METHOD = "FAST" order by 1, 2, 3;
select TABLE_SCHEMA, MVIEW_NAME, REFRESH_METHOD from information_schema.tidb_mviews where REFRESH_METHOD != "FAST" order by 1, 2, 3;
select TABLE_SCHEMA, MVIEW_NAME, MVIEW_MODIFY_TIME, REFRESH_METHOD from information_schema.tidb_mviews where MVIEW_NAME in ("mv_t", "mv", "mv_t1") and REFRESH_METHOD = "FAST" order by 1, 2, 3;
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟠 Major | ⚡ Quick win

Don’t snapshot raw MVIEW_MODIFY_TIME in the golden output.

Projecting MVIEW_MODIFY_TIME here bakes wall-clock timestamps into infoschema_mv.result, so a clean regeneration will differ even when behavior is correct. Prefer a stable assertion such as MVIEW_MODIFY_TIME is not null or another predicate that does not depend on the creation timestamp. As per coding guidelines, tests/integrationtest/t/**: Integration test files changed: record and verify regenerated result correctness.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@tests/integrationtest/t/executor/infoschema_mv.test` around lines 45 - 51,
The test currently snapshots raw MVIEW_MODIFY_TIME (queries selecting
MVIEW_MODIFY_TIME from information_schema.tidb_mviews), which bakes wall-clock
timestamps into infoschema_mv.result; update the test in
tests/integrationtest/t/infoschema_mv.test to stop capturing the raw
timestamp—either remove MVIEW_MODIFY_TIME from the SELECT projections or replace
that projection with a stable predicate/assertion (e.g., assert
MVIEW_MODIFY_TIME IS NOT NULL or use a deterministic flag column) in the queries
that reference MVIEW_MODIFY_TIME so the golden output is stable across
regenerations.

@codecov
Copy link
Copy Markdown

codecov Bot commented Jun 1, 2026

Codecov Report

❌ Patch coverage is 0% with 545 lines in your changes missing coverage. Please review.
⚠️ Please upload report for BASE (feature/release-8.5-materialized-view-2603@e8c6e40). Learn more about missing BASE report.

Additional details and impacted files
@@                               Coverage Diff                               @@
##             feature/release-8.5-materialized-view-2603     #68839   +/-   ##
===============================================================================
  Coverage                                              ?   22.4065%           
===============================================================================
  Files                                                 ?       1712           
  Lines                                                 ?     645699           
  Branches                                              ?          0           
===============================================================================
  Hits                                                  ?     144679           
  Misses                                                ?     482907           
  Partials                                              ?      18113           
Flag Coverage Δ
integration 22.4065% <0.0000%> (?)

Flags with carried forward coverage won't be shown. Click here to find out more.

Components Coverage Δ
dumpling ∅ <0.0000%> (?)
parser ∅ <0.0000%> (?)
br 23.7784% <0.0000%> (?)
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@ti-chi-bot
Copy link
Copy Markdown

ti-chi-bot Bot commented Jun 2, 2026

@xzhangxian1008: The following tests failed, say /retest to rerun all failed tests or /retest-required to rerun all mandatory failed tests:

Test name Commit Details Required Rerun command
idc-jenkins-ci-tidb/mysql-test c26c43b link true /test mysql-test
idc-jenkins-ci-tidb/check_dev c26c43b link true /test check-dev
pull-br-integration-test c26c43b link true /test pull-br-integration-test
idc-jenkins-ci-tidb/unit-test c26c43b link true /test unit-test
idc-jenkins-ci-tidb/check_dev_2 c26c43b link true /test check-dev2

Full PR test history. Your PR dashboard.

Details

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository. I understand the commands that are listed here.

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

Labels

release-note Denotes a PR that will be considered when it comes time to generate release notes. sig/planner SIG: Planner size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant