-
Notifications
You must be signed in to change notification settings - Fork 3.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[improvement](statistics)Drop column stats after schema change. (#39101)
Drop column stats after schema change. So the auto analyze could be triggered and will collect stats under new schema.
- Loading branch information
1 parent
7abcbed
commit c6be1b9
Showing
6 changed files
with
206 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
171 changes: 171 additions & 0 deletions
171
regression-test/suites/statistics/test_schema_change_statistics.groovy
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,171 @@ | ||
// Licensed to the Apache Software Foundation (ASF) under one | ||
// or more contributor license agreements. See the NOTICE file | ||
// distributed with this work for additional information | ||
// regarding copyright ownership. The ASF licenses this file | ||
// to you under the Apache License, Version 2.0 (the | ||
// "License"); you may not use this file except in compliance | ||
// with the License. You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, | ||
// software distributed under the License is distributed on an | ||
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
// KIND, either express or implied. See the License for the | ||
// specific language governing permissions and limitations | ||
// under the License. | ||
|
||
suite("test_schema_change_statistics") { | ||
|
||
def wait_schema_change_finished = { -> | ||
Thread.sleep(1000) | ||
def result = sql """SHOW ALTER TABLE COLUMN from test_schema_change_statistics""" | ||
boolean finished = false; | ||
for (int i = 0; i < 120; i++) { | ||
finished = true; | ||
for (int j = 0; j < result.size(); j++) { | ||
if (result[j][9] != "FINISHED") { | ||
finished = false; | ||
break; | ||
} | ||
} | ||
if (finished) { | ||
break; | ||
} | ||
logger.info("Schema change not finished yet: " + result) | ||
result = sql """SHOW ALTER TABLE COLUMN from test_schema_change_statistics""" | ||
Thread.sleep(1000) | ||
} | ||
} | ||
|
||
def stats_dropped = { table -> | ||
def result1 = sql """show column cached stats $table""" | ||
def result2 = sql """show column stats $table""" | ||
boolean dropped = false | ||
for (int i = 0; i < 120; i++) { | ||
if (0 == result1.size() && 0 == result2.size()) { | ||
dropped = true; | ||
break; | ||
} | ||
Thread.sleep(1000) | ||
result1 = sql """show column cached stats $table""" | ||
result2 = sql """show column stats $table""" | ||
} | ||
assertTrue(dropped) | ||
} | ||
|
||
sql """drop database if exists test_schema_change_statistics""" | ||
sql """create database test_schema_change_statistics""" | ||
sql """use test_schema_change_statistics""" | ||
sql """set global force_sample_analyze=false""" | ||
sql """set global enable_auto_analyze=false""" | ||
|
||
|
||
sql """CREATE TABLE change ( | ||
key1 bigint NOT NULL, | ||
key2 bigint NOT NULL, | ||
value1 int NOT NULL, | ||
value2 int NOT NULL, | ||
value3 int NOT NULL | ||
)ENGINE=OLAP | ||
DUPLICATE KEY(`key1`, `key2`) | ||
COMMENT "OLAP" | ||
DISTRIBUTED BY HASH(`key1`) BUCKETS 2 | ||
PROPERTIES ("replication_num" = "1"); | ||
""" | ||
createMV("create materialized view mv1 as select key1,value1,value2 from change;") | ||
sql """insert into change values (1, 2, 3, 4, 5), (1, 2, 3, 4, 5), (10, 20, 30, 40, 50), (10, 20, 30, 40, 50), (100, 200, 300, 400, 500), (1001, 2001, 3001, 4001, 5001);""" | ||
|
||
sql """analyze table change with sync;""" | ||
def result = sql """show column stats change""" | ||
assertEquals(8, result.size()) | ||
result = sql """show column cached stats change""" | ||
assertEquals(8, result.size()) | ||
|
||
sql """ALTER TABLE change ADD COLUMN new_value INT DEFAULT "0" AFTER value3;""" | ||
stats_dropped("change") | ||
|
||
sql """analyze table change with sync;""" | ||
result = sql """show column stats change""" | ||
assertEquals(9, result.size()) | ||
result = sql """show column cached stats change""" | ||
assertEquals(9, result.size()) | ||
|
||
sql """ALTER TABLE change DROP COLUMN new_value;""" | ||
stats_dropped("change") | ||
|
||
sql """analyze table change with sync;""" | ||
result = sql """show column stats change""" | ||
assertEquals(8, result.size()) | ||
result = sql """show column cached stats change""" | ||
assertEquals(8, result.size()) | ||
|
||
sql """ALTER TABLE change DROP COLUMN mv_value1 from mv1;""" | ||
wait_schema_change_finished() | ||
stats_dropped("change") | ||
|
||
sql """analyze table change with sync;""" | ||
result = sql """show column stats change""" | ||
assertEquals(7, result.size()) | ||
result = sql """show column cached stats change""" | ||
assertEquals(7, result.size()) | ||
|
||
sql """ALTER TABLE change ADD COLUMN new_key INT key DEFAULT "0" AFTER key2;""" | ||
wait_schema_change_finished() | ||
stats_dropped("change") | ||
|
||
sql """analyze table change with sync;""" | ||
result = sql """show column stats change""" | ||
assertEquals(8, result.size()) | ||
result = sql """show column cached stats change""" | ||
assertEquals(8, result.size()) | ||
|
||
sql """ALTER TABLE change DROP COLUMN new_key;""" | ||
wait_schema_change_finished() | ||
stats_dropped("change") | ||
|
||
sql """analyze table change with sync;""" | ||
result = sql """show column stats change""" | ||
assertEquals(7, result.size()) | ||
result = sql """show column cached stats change""" | ||
assertEquals(7, result.size()) | ||
|
||
sql """ALTER TABLE change MODIFY COLUMN value2 BIGINT AFTER value3;""" | ||
wait_schema_change_finished() | ||
stats_dropped("change") | ||
|
||
sql """analyze table change with sync;""" | ||
result = sql """show column stats change""" | ||
assertEquals(7, result.size()) | ||
result = sql """show column cached stats change""" | ||
assertEquals(7, result.size()) | ||
|
||
|
||
sql """CREATE TABLE change_no_index ( | ||
key1 bigint NOT NULL, | ||
key2 bigint NOT NULL, | ||
value1 int NOT NULL, | ||
value2 int NOT NULL, | ||
value3 int NOT NULL | ||
)ENGINE=OLAP | ||
DUPLICATE KEY(`key1`, `key2`) | ||
COMMENT "OLAP" | ||
DISTRIBUTED BY HASH(`key1`) BUCKETS 2 | ||
PROPERTIES ("replication_num" = "1"); | ||
""" | ||
|
||
sql """insert into change_no_index values (1, 2, 3, 4, 5), (1, 2, 3, 4, 5), (10, 20, 30, 40, 50), (10, 20, 30, 40, 50), (100, 200, 300, 400, 500), (1001, 2001, 3001, 4001, 5001);""" | ||
sql """analyze table change_no_index with sync;""" | ||
result = sql """show column stats change_no_index""" | ||
assertEquals(5, result.size()) | ||
result = sql """show column cached stats change_no_index""" | ||
assertEquals(5, result.size()) | ||
|
||
sql """ALTER TABLE change_no_index RENAME COLUMN value1 value1_new;""" | ||
wait_schema_change_finished() | ||
stats_dropped("change_no_index") | ||
|
||
|
||
sql """drop database if exists test_schema_change_statistics""" | ||
} | ||
|