-
Notifications
You must be signed in to change notification settings - Fork 1.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Feature] Support assign sort key of primary key model by schema change reorder. #13642
[Feature] Support assign sort key of primary key model by schema change reorder. #13642
Conversation
clang-tidy review says "All clean, LGTM! 👍" |
clang-tidy review says "All clean, LGTM! 👍" |
clang-tidy review says "All clean, LGTM! 👍" |
throw new DdlException("Primary key table do not support reorder column"); | ||
List<Integer> sortKeyIdxes = new ArrayList<>(); | ||
processReorderColumnOfPrimaryKey((ReorderColumnsClause) alterClause, olapTable, indexSchemaMap, sortKeyIdxes); | ||
return createJobForProcessReorderColumnOfPrimaryKey(db.getId(), olapTable, | ||
indexSchemaMap, sortKeyIdxes); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
what if a user made a mistake and use the old usage of alter table order by
, for example:
create table table0 (a,b,c,d,e) primary key(a), order by(c,d)
alter table order by (d, c, b, c, e)
Could we provide a notice of potential misusage if the user provides all the columns in the table in alter table order by
for primary key table?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
old usage 1. need all columns. 2. all keys need be the prefix of all columns. 3. column can not be duplicate appear.
if write all columns, we can not tell the differences between make all columns to be sort key on purpose and making a mistake to use the old usage.
maybe the furthest the judgement can do is provide a notice when satisfy 1, 2, since that in the new usage 2 is needless.
bdda272
to
fd21ee4
Compare
…ema change reorder.
…d more strict NotSupport logic branch.
fd21ee4
to
0f89d07
Compare
run starrocks_be_unittest |
clang-tidy review says "All clean, LGTM! 👍" |
Kudos, SonarCloud Quality Gate passed! |
[FE PR Coverage Check]😞 fail : 13 / 43 (30.23%) file detail
|
clang-tidy review says "All clean, LGTM! 👍" |
run starrocks_admit_test |
Kudos, SonarCloud Quality Gate passed! 0 Bugs No Coverage information |
clang-tidy review says "All clean, LGTM! 👍" |
… key model by schema change reorder. (StarRocks#13642) `` MySQL [test]> CREATE TABLE test ( -> `k1` int, -> `k2` int, -> `k3` int, -> `v1` int, -> `v2` int, -> `v3` int, -> `v4` int, -> `v5` int -> ) ENGINE=OLAP -> PRIMARY KEY(`k1`, `k2`, `k3`) -> COMMENT "OLAP" -> DISTRIBUTED BY HASH(`k1`, `k2`, `k3`) BUCKETS 1 -> ORDER BY(`v2`, `v3`) -> PROPERTIES ("replication_num" = "1"); Query OK, 0 rows affected (0.11 sec) MySQL [test]> ALTER TABLE test ORDER BY (v3, v2); Primary key table do not support reorder column ``` should be: ``` MySQL [test]> select v2, v3 from test; +------+------+ | v2 | v3 | +------+------+ | 1 | 5 | | 2 | 4 | | 3 | 3 | | 4 | 2 | | 5 | 1 | +------+------+ 5 rows in set (0.02 sec) MySQL [test]> show create table test; +-------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ | Table | Create Table | +-------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ | test | CREATE TABLE `test` ( `k1` int(11) NOT NULL COMMENT "", `k2` int(11) NOT NULL COMMENT "", `k3` int(11) NOT NULL COMMENT "", `v1` int(11) NULL COMMENT "", `v2` int(11) NULL COMMENT "", `v3` int(11) NULL COMMENT "", `v4` int(11) NULL COMMENT "", `v5` int(11) NULL COMMENT "" ) ENGINE=OLAP PRIMARY KEY(`k1`, `k2`, `k3`) COMMENT "OLAP" DISTRIBUTED BY HASH(`k1`, `k2`, `k3`) BUCKETS 1 ORDER BY(`v2`, `v3`) PROPERTIES ( "replication_num" = "1", "in_memory" = "false", "storage_format" = "DEFAULT", "enable_persistent_index" = "false", "compression" = "LZ4" ); | +-------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ 1 row in set (0.01 sec) MySQL [test]> ALTER TABLE test ORDER BY (v3, v2); Query OK, 0 rows affected (0.03 sec) MySQL [test]> select v3, v2 from test; +------+------+ | v3 | v2 | +------+------+ | 1 | 5 | | 2 | 4 | | 3 | 3 | | 4 | 2 | | 5 | 1 | +------+------+ 5 rows in set (0.01 sec) MySQL [test]> show create table test; +-------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ | Table | Create Table | +-------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ | test | CREATE TABLE `test` ( `k1` int(11) NOT NULL COMMENT "", `k2` int(11) NOT NULL COMMENT "", `k3` int(11) NOT NULL COMMENT "", `v1` int(11) NULL COMMENT "", `v2` int(11) NULL COMMENT "", `v3` int(11) NULL COMMENT "", `v4` int(11) NULL COMMENT "", `v5` int(11) NULL COMMENT "" ) ENGINE=OLAP PRIMARY KEY(`k1`, `k2`, `k3`) COMMENT "OLAP" DISTRIBUTED BY HASH(`k1`, `k2`, `k3`) BUCKETS 1 ORDER BY(`v3`, `v2`) PROPERTIES ( "replication_num" = "1", "in_memory" = "false", "storage_format" = "DEFAULT", "enable_persistent_index" = "false", "compression" = "LZ4" ); | +-------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ 1 row in set (0.01 sec) ```
…ge reorder. (#13642) (#14930) * [cherry-pick][branch-2.5][Feature] Support assign sort key of primary key model by schema change reorder. (#13642) `` MySQL [test]> CREATE TABLE test ( -> `k1` int, -> `k2` int, -> `k3` int, -> `v1` int, -> `v2` int, -> `v3` int, -> `v4` int, -> `v5` int -> ) ENGINE=OLAP -> PRIMARY KEY(`k1`, `k2`, `k3`) -> COMMENT "OLAP" -> DISTRIBUTED BY HASH(`k1`, `k2`, `k3`) BUCKETS 1 -> ORDER BY(`v2`, `v3`) -> PROPERTIES ("replication_num" = "1"); Query OK, 0 rows affected (0.11 sec) MySQL [test]> ALTER TABLE test ORDER BY (v3, v2); Primary key table do not support reorder column ``` should be: ``` MySQL [test]> select v2, v3 from test; +------+------+ | v2 | v3 | +------+------+ | 1 | 5 | | 2 | 4 | | 3 | 3 | | 4 | 2 | | 5 | 1 | +------+------+ 5 rows in set (0.02 sec) MySQL [test]> show create table test; +-------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ | Table | Create Table | +-------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ | test | CREATE TABLE `test` ( `k1` int(11) NOT NULL COMMENT "", `k2` int(11) NOT NULL COMMENT "", `k3` int(11) NOT NULL COMMENT "", `v1` int(11) NULL COMMENT "", `v2` int(11) NULL COMMENT "", `v3` int(11) NULL COMMENT "", `v4` int(11) NULL COMMENT "", `v5` int(11) NULL COMMENT "" ) ENGINE=OLAP PRIMARY KEY(`k1`, `k2`, `k3`) COMMENT "OLAP" DISTRIBUTED BY HASH(`k1`, `k2`, `k3`) BUCKETS 1 ORDER BY(`v2`, `v3`) PROPERTIES ( "replication_num" = "1", "in_memory" = "false", "storage_format" = "DEFAULT", "enable_persistent_index" = "false", "compression" = "LZ4" ); | +-------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ 1 row in set (0.01 sec) MySQL [test]> ALTER TABLE test ORDER BY (v3, v2); Query OK, 0 rows affected (0.03 sec) MySQL [test]> select v3, v2 from test; +------+------+ | v3 | v2 | +------+------+ | 1 | 5 | | 2 | 4 | | 3 | 3 | | 4 | 2 | | 5 | 1 | +------+------+ 5 rows in set (0.01 sec) MySQL [test]> show create table test; +-------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ | Table | Create Table | +-------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ | test | CREATE TABLE `test` ( `k1` int(11) NOT NULL COMMENT "", `k2` int(11) NOT NULL COMMENT "", `k3` int(11) NOT NULL COMMENT "", `v1` int(11) NULL COMMENT "", `v2` int(11) NULL COMMENT "", `v3` int(11) NULL COMMENT "", `v4` int(11) NULL COMMENT "", `v5` int(11) NULL COMMENT "" ) ENGINE=OLAP PRIMARY KEY(`k1`, `k2`, `k3`) COMMENT "OLAP" DISTRIBUTED BY HASH(`k1`, `k2`, `k3`) BUCKETS 1 ORDER BY(`v3`, `v2`) PROPERTIES ( "replication_num" = "1", "in_memory" = "false", "storage_format" = "DEFAULT", "enable_persistent_index" = "false", "compression" = "LZ4" ); | +-------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ 1 row in set (0.01 sec) ``` * resolve conflict.
…ge reorder. (#13642) `` MySQL [test]> CREATE TABLE test ( -> `k1` int, -> `k2` int, -> `k3` int, -> `v1` int, -> `v2` int, -> `v3` int, -> `v4` int, -> `v5` int -> ) ENGINE=OLAP -> PRIMARY KEY(`k1`, `k2`, `k3`) -> COMMENT "OLAP" -> DISTRIBUTED BY HASH(`k1`, `k2`, `k3`) BUCKETS 1 -> ORDER BY(`v2`, `v3`) -> PROPERTIES ("replication_num" = "1"); Query OK, 0 rows affected (0.11 sec) MySQL [test]> ALTER TABLE test ORDER BY (v3, v2); Primary key table do not support reorder column ``` should be: ``` MySQL [test]> select v2, v3 from test; +------+------+ | v2 | v3 | +------+------+ | 1 | 5 | | 2 | 4 | | 3 | 3 | | 4 | 2 | | 5 | 1 | +------+------+ 5 rows in set (0.02 sec) MySQL [test]> show create table test; +-------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ | Table | Create Table | +-------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ | test | CREATE TABLE `test` ( `k1` int(11) NOT NULL COMMENT "", `k2` int(11) NOT NULL COMMENT "", `k3` int(11) NOT NULL COMMENT "", `v1` int(11) NULL COMMENT "", `v2` int(11) NULL COMMENT "", `v3` int(11) NULL COMMENT "", `v4` int(11) NULL COMMENT "", `v5` int(11) NULL COMMENT "" ) ENGINE=OLAP PRIMARY KEY(`k1`, `k2`, `k3`) COMMENT "OLAP" DISTRIBUTED BY HASH(`k1`, `k2`, `k3`) BUCKETS 1 ORDER BY(`v2`, `v3`) PROPERTIES ( "replication_num" = "1", "in_memory" = "false", "storage_format" = "DEFAULT", "enable_persistent_index" = "false", "compression" = "LZ4" ); | +-------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ 1 row in set (0.01 sec) MySQL [test]> ALTER TABLE test ORDER BY (v3, v2); Query OK, 0 rows affected (0.03 sec) MySQL [test]> select v3, v2 from test; +------+------+ | v3 | v2 | +------+------+ | 1 | 5 | | 2 | 4 | | 3 | 3 | | 4 | 2 | | 5 | 1 | +------+------+ 5 rows in set (0.01 sec) MySQL [test]> show create table test; +-------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ | Table | Create Table | +-------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ | test | CREATE TABLE `test` ( `k1` int(11) NOT NULL COMMENT "", `k2` int(11) NOT NULL COMMENT "", `k3` int(11) NOT NULL COMMENT "", `v1` int(11) NULL COMMENT "", `v2` int(11) NULL COMMENT "", `v3` int(11) NULL COMMENT "", `v4` int(11) NULL COMMENT "", `v5` int(11) NULL COMMENT "" ) ENGINE=OLAP PRIMARY KEY(`k1`, `k2`, `k3`) COMMENT "OLAP" DISTRIBUTED BY HASH(`k1`, `k2`, `k3`) BUCKETS 1 ORDER BY(`v3`, `v2`) PROPERTIES ( "replication_num" = "1", "in_memory" = "false", "storage_format" = "DEFAULT", "enable_persistent_index" = "false", "compression" = "LZ4" ); | +-------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ 1 row in set (0.01 sec) ``` (cherry picked from commit d25e71b) # Conflicts: # be/src/storage/tablet_updates.cpp # be/test/exprs/vectorized/math_functions_test.cpp # be/test/storage/tablet_updates_test.cpp
✅ Backports have been created
|
…e with separate primary key and sort key (#20035) If we create a primary key table with a separate primary key and sort key, BE maybe crash if we do a schema change in the table(add column/drop column) The reason is that we use column id as the sort key index in the tablet, and we only support reordering the sort key in this pr(#13642) which assumes the number of columns in the origin tablet and new tablet during schema change is the same. However, if we add/drop a column, the sort key index in the new tablet will be different from the origin tablet and we will execute reorder which may cause BE crash. Signed-off-by: zhangqiang <[email protected]>
…e with separate primary key and sort key (#20035) If we create a primary key table with a separate primary key and sort key, BE maybe crash if we do a schema change in the table(add column/drop column) The reason is that we use column id as the sort key index in the tablet, and we only support reordering the sort key in this pr(#13642) which assumes the number of columns in the origin tablet and new tablet during schema change is the same. However, if we add/drop a column, the sort key index in the new tablet will be different from the origin tablet and we will execute reorder which may cause BE crash. Signed-off-by: zhangqiang <[email protected]> (cherry picked from commit 82f9d31)
…e with separate primary key and sort key (#20035) If we create a primary key table with a separate primary key and sort key, BE maybe crash if we do a schema change in the table(add column/drop column) The reason is that we use column id as the sort key index in the tablet, and we only support reordering the sort key in this pr(#13642) which assumes the number of columns in the origin tablet and new tablet during schema change is the same. However, if we add/drop a column, the sort key index in the new tablet will be different from the origin tablet and we will execute reorder which may cause BE crash. Signed-off-by: zhangqiang <[email protected]> (cherry picked from commit 82f9d31)
…e with separate primary key and sort key (#20035) If we create a primary key table with a separate primary key and sort key, BE maybe crash if we do a schema change in the table(add column/drop column) The reason is that we use column id as the sort key index in the tablet, and we only support reordering the sort key in this pr(#13642) which assumes the number of columns in the origin tablet and new tablet during schema change is the same. However, if we add/drop a column, the sort key index in the new tablet will be different from the origin tablet and we will execute reorder which may cause BE crash. Signed-off-by: zhangqiang <[email protected]> (cherry picked from commit 82f9d31)
…e with separate primary key and sort key (StarRocks#20035) If we create a primary key table with a separate primary key and sort key, BE maybe crash if we do a schema change in the table(add column/drop column) The reason is that we use column id as the sort key index in the tablet, and we only support reordering the sort key in this pr(StarRocks#13642) which assumes the number of columns in the origin tablet and new tablet during schema change is the same. However, if we add/drop a column, the sort key index in the new tablet will be different from the origin tablet and we will execute reorder which may cause BE crash. Signed-off-by: zhangqiang <[email protected]>
…e with separate primary key and sort key (StarRocks#20035) If we create a primary key table with a separate primary key and sort key, BE maybe crash if we do a schema change in the table(add column/drop column) The reason is that we use column id as the sort key index in the tablet, and we only support reordering the sort key in this pr(StarRocks#13642) which assumes the number of columns in the origin tablet and new tablet during schema change is the same. However, if we add/drop a column, the sort key index in the new tablet will be different from the origin tablet and we will execute reorder which may cause BE crash. Signed-off-by: zhangqiang <[email protected]>
…e with separate primary key and sort key (StarRocks#20035) If we create a primary key table with a separate primary key and sort key, BE maybe crash if we do a schema change in the table(add column/drop column) The reason is that we use column id as the sort key index in the tablet, and we only support reordering the sort key in this pr(StarRocks#13642) which assumes the number of columns in the origin tablet and new tablet during schema change is the same. However, if we add/drop a column, the sort key index in the new tablet will be different from the origin tablet and we will execute reorder which may cause BE crash. Signed-off-by: zhangqiang <[email protected]>
What type of PR is this:
Which issues of this PR fixes :
Fixes #12684 #11733
Problem Summary(Required) :
do not support assign sort key of primary key model by schema change reorder now:
should be:
Checklist: