XnY-wei opened a new pull request, #65519:
URL: https://github.com/apache/doris/pull/65519
### What problem does this PR solve?
Issue Number: close #xxx
Related PR: #xxx
Problem Summary:
Previously, users had to drop and recreate an asynchronous
materialized view (MTMV) whenever they needed an additional
derived column. This is expensive because it forces a full
rebuild and invalidates downstream query rewriting.
This PR introduces `ALTER MATERIALIZED VIEW <mv> ADD COLUMN
<col> AS <expr>`, which lets users evolve the MTMV schema
in place by appending a new column derived from an expression
over the existing query.
`CREATE TABLE orders (
o_orderkey bigint NOT NULL,
o_custkey int NOT NULL,
o_orderstatus varchar(1) NOT NULL,
o_totalprice decimal(15,2) NOT NULL,
o_orderdate date NOT NULL,
o_orderpriority varchar(15) NOT NULL,
o_clerk varchar(15) NOT NULL,
o_shippriority int NOT NULL,
o_comment varchar(79) NOT NULL
) ENGINE=OLAP
DUPLICATE KEY(o_orderkey, o_custkey)
PARTITION BY RANGE(o_orderdate)
(PARTITION p_20240101 VALUES [('2024-01-01'), ('2024-02-01')),
PARTITION p_20240201 VALUES [('2024-02-01'), ('2024-03-01')),
PARTITION p_20240301 VALUES [('2024-03-01'), ('2024-04-01')))
DISTRIBUTED BY HASH(o_orderkey) BUCKETS 16
PROPERTIES (
"replication_allocation" = "tag.location.default: 1",
"min_load_replica_num" = "-1",
"is_being_synced" = "false",
"storage_medium" = "hdd",
"storage_format" = "V2",
"inverted_index_storage_format" = "V3",
"light_schema_change" = "true",
"disable_auto_compaction" = "false",
"enable_single_replica_compaction" = "false",
"group_commit_interval_ms" = "10000",
"group_commit_data_bytes" = "134217728"
);
mysql> CREATE MATERIALIZED VIEW orders_async_mv
-> BUILD IMMEDIATE
-> REFRESH AUTO
-> ON SCHEDULE EVERY 1 DAY
-> DISTRIBUTED BY RANDOM BUCKETS 2
-> PROPERTIES ('replication_num' = '1')
-> AS
-> SELECT
-> DATE_TRUNC(o_orderdate, 'MONTH') AS order_month,
-> SUM(o_totalprice) AS total_price
-> FROM orders
-> GROUP BY
-> DATE_TRUNC(o_orderdate, 'MONTH');
Query OK, 0 rows affected (0.11 sec)
mysql> INSERT INTO orders
-> (o_orderkey, o_custkey, o_orderstatus, o_totalprice, o_orderdate,
o_orderpriority, o_clerk, o_shippriority, o_comment)
-> VALUES
-> (1, 100, 'O', 1000.00, '2024-01-01', '1-URGENT', 'Clerk#000000001', 1,
'first order'),
-> (2, 101, 'F', 2000.00, '2024-02-01', '2-HIGH', 'Clerk#000000002', 2,
'second order'),
-> (3, 102, 'O', 3000.00, '2024-03-01', '3-MEDIUM', 'Clerk#000000003', 0,
'third order');
Query OK, 10 rows affected (0.21 sec)
{'label':'label_bbe60eaaa7dc43dc_831c715aeabb1684', 'status':'VISIBLE',
'txnId':'2013'}
mysql> select * from orders_async_mv;
Empty set (0.02 sec)
mysql> REFRESH MATERIALIZED VIEW orders_async_mv COMPLETE;
Query OK, 0 rows affected (0.02 sec)
mysql> select * from orders_async_mv;
+-------------+-------------+
| order_month | total_price |
+-------------+-------------+
| 2024-01-01 | 1000.00 |
| 2024-02-01 | 2000.00 |
| 2024-03-01 | 3000.00 |
+-------------+-------------+
3 rows in set (0.03 sec)
mysql> ALTER MATERIALIZED VIEW orders_async_mv ADD COLUMN total_orderkey INT
NULL AS sum(o_orderke
y);
Query OK, 0 rows affected (0.01 sec)
mysql> select * from orders_async_mv;
+-------------+-------------+----------------+
| order_month | total_price | total_orderkey |
+-------------+-------------+----------------+
| 2024-01-01 | 1000.00 | NULL |
| 2024-02-01 | 2000.00 | NULL |
| 2024-03-01 | 3000.00 | NULL |
+-------------+-------------+----------------+
3 rows in set (0.05 sec)
mysql> REFRESH MATERIALIZED VIEW orders_async_mv COMPLETE;
Query OK, 0 rows affected (0.00 sec)
mysql> select * from orders_async_mv;
+-------------+-------------+----------------+
| order_month | total_price | total_orderkey |
+-------------+-------------+----------------+
| 2024-01-01 | 1000.00 | 1 |
| 2024-02-01 | 2000.00 | 2 |
| 2024-03-01 | 3000.00 | 3 |
+-------------+-------------+----------------+
3 rows in set (0.03 sec)`
### Release note
None
### Check List (For Author)
- Test <!-- At least one of them must be included. -->
- [ ] Regression test
- [ ] Unit Test
- [ ] Manual test (add detailed scripts or steps below)
- [ ] No need to test or manual test. Explain why:
- [ ] This is a refactor/code format and no logic has been changed.
- [ ] Previous test can cover this change.
- [ ] No code files have been changed.
- [ ] Other reason <!-- Add your reason? -->
- Behavior changed:
- [ ] No.
- [ ] Yes. <!-- Explain the behavior change -->
- Does this need documentation?
- [ ] No.
- [ ] Yes. <!-- Add document PR link here. eg:
https://github.com/apache/doris-website/pull/1214 -->
### Check List (For Reviewer who merge this PR)
- [ ] Confirm the release note
- [ ] Confirm test cases
- [ ] Confirm document
- [ ] Add branch pick label <!-- Add branch pick label that this PR should
merge into -->
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]