Commit a5fe8de
authored
feat(meta): add materialized view metadata support (#20184)
* feat(meta): add materialized view definition and source index support
Persist materialized view definitions under MV table IDs.
When commit_table_meta publishes a staged MV, read the source table ID from its TableMeta options and update the source-table-to-MV index in the same transaction. CREATE OR REPLACE replaces the previous MV index membership while retaining superseded definitions for GC.
Explicit MV drop removes its definition and source-index membership. Table GC cleans up retained definitions and source-index keys.
* refactor mget_mvs_by_source_table_id and remove get_mv_ids_by_source_table_id
* refactor mget_mvs_by_source_table_id return, add source_index_seq
* add source-table and mv consistency in src/meta/api/src/api_impl/materialized_view_api.rs; add MVDefinition::schema comment in materialized_view.proto
* feat(meta): add sync creation mode to materialized view metadata
- add immutable MVDefinition.sync_creation
- rename schema to logical_schema to distinguish it from TableMeta.schema
* when create mv engine table create_table(as_dropped=false) and commit_table_meta do not process mv
* split vec
* feat(meta): track materialized view source generations
Replace the EmptyProto values of SourceTableMVIdent and MVSourceBindingVersionIdent with explicit generation records.
SourceTableMVIdent must represent both a durable dependency and the source generation against which an MV was built. With EmptyProto, invalidation could only be represented by deleting the relationship key. MV-invalidating source DDL would therefore require O(N) deletes and would lose the dependency needed by SHOW, refresh, DROP, and GC.
MVSourceBinding stores bound_source_generation instead. The relationship remains present after invalidating column DDL, and validity is derived by comparing the bound generation with the current source generation. Refresh can make one MV valid again by updating its relationship to the current generation.
MVSourceBindingVersionIdent also cannot use EmptyProto with its KV sequence as the semantic generation. A missing key is observed as generation 0, but its first put receives a nonzero KV sequence. An edge atomically created with bound generation 0 would therefore be stale immediately. Initializing the key in a separate transaction would leave metadata behind when CREATE MV fails and complicate concurrent CREATE operations.
MVSourceBindingVersion stores current_source_generation explicitly. This lets the first successful CREATE publish current generation 0 and an edge bound to generation 0 in one transaction. The KV sequence remains internal to the Meta API as a CAS token.
Advance the source generation only for DDL that invalidates existing MV bindings: RENAME COLUMN, DROP COLUMN, and MODIFY COLUMN. ADD COLUMN and RENAME TABLE preserve MV binding metadata. Source DROP and UNDROP also preserve the relationship and version records for the same source table identity, while source GC removes them.
Split dependency lookup into an unfiltered API for lifecycle operations and a generation-filtered API for query and maintenance paths. Validate the expected source generation during CREATE and document the CREATE, REFRESH, source DDL, DROP, UNDROP, and GC transaction contracts.
Update the unreleased v181 protobuf records and compatibility tests.1 parent 2501da7 commit a5fe8de
36 files changed
Lines changed: 1727 additions & 41 deletions
File tree
- src
- common/exception/src
- meta
- api/src
- api_impl
- app/src
- schema
- materialized_view
- table
- binaries/metabench
- process/src
- proto-conv
- src
- impls
- tests/it
- protos/proto
- schema-api-test-suite/src
- query
- ee/src
- attach_table
- stream
- service
- src/interpreters
- tests/it
- catalogs
- storages
- storages/common/table_meta
- src/table
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
525 | 525 | | |
526 | 526 | | |
527 | 527 | | |
528 | | - | |
| 528 | + | |
529 | 529 | | |
530 | 530 | | |
531 | 531 | | |
| |||
569 | 569 | | |
570 | 570 | | |
571 | 571 | | |
| 572 | + | |
| 573 | + | |
| 574 | + | |
| 575 | + | |
572 | 576 | | |
573 | 577 | | |
574 | 578 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
129 | 129 | | |
130 | 130 | | |
131 | 131 | | |
| 132 | + | |
132 | 133 | | |
133 | 134 | | |
134 | 135 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
38 | 38 | | |
39 | 39 | | |
40 | 40 | | |
| 41 | + | |
| 42 | + | |
41 | 43 | | |
42 | 44 | | |
| 45 | + | |
| 46 | + | |
43 | 47 | | |
44 | 48 | | |
45 | 49 | | |
| |||
51 | 55 | | |
52 | 56 | | |
53 | 57 | | |
| 58 | + | |
54 | 59 | | |
55 | 60 | | |
56 | 61 | | |
| |||
772 | 777 | | |
773 | 778 | | |
774 | 779 | | |
| 780 | + | |
| 781 | + | |
| 782 | + | |
| 783 | + | |
| 784 | + | |
| 785 | + | |
| 786 | + | |
| 787 | + | |
| 788 | + | |
| 789 | + | |
| 790 | + | |
| 791 | + | |
| 792 | + | |
| 793 | + | |
| 794 | + | |
| 795 | + | |
| 796 | + | |
| 797 | + | |
| 798 | + | |
| 799 | + | |
| 800 | + | |
| 801 | + | |
| 802 | + | |
| 803 | + | |
| 804 | + | |
| 805 | + | |
| 806 | + | |
| 807 | + | |
| 808 | + | |
| 809 | + | |
| 810 | + | |
| 811 | + | |
| 812 | + | |
| 813 | + | |
| 814 | + | |
| 815 | + | |
| 816 | + | |
| 817 | + | |
| 818 | + | |
775 | 819 | | |
776 | 820 | | |
777 | 821 | | |
| |||
0 commit comments