Skip to content
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

Conversation

Linkerist
Copy link
Contributor

@Linkerist Linkerist commented Nov 18, 2022

What type of PR is this:

  • BugFix
  • Feature
  • Enhancement
  • Refactor
  • UT
  • Doc
  • Tool

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:

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)

Checklist:

  • I have added test cases for my bug fix or my new feature
  • This pr will affect users' behaviors
  • This pr needs user documentation (for new or modified features or behaviors)
    • I have added documentation for my new feature or new function

@github-actions
Copy link

clang-tidy review says "All clean, LGTM! 👍"

be/src/bench/CMakeLists.txt Outdated Show resolved Hide resolved
be/src/storage/rowset/rowset_writer.cpp Show resolved Hide resolved
@github-actions
Copy link

clang-tidy review says "All clean, LGTM! 👍"

@github-actions
Copy link

clang-tidy review says "All clean, LGTM! 👍"

be/src/storage/rowset/rowset_writer.cpp Outdated Show resolved Hide resolved
Comment on lines -1153 to +1212
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);
Copy link
Contributor

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?

Copy link
Contributor Author

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.

@github-actions github-actions bot removed the be-build label Nov 29, 2022
@Linkerist Linkerist force-pushed the feature_support_schema_change_reorder_primary_key_model_sort_key branch from bdda272 to fd21ee4 Compare December 2, 2022 04:07
@Linkerist Linkerist force-pushed the feature_support_schema_change_reorder_primary_key_model_sort_key branch from fd21ee4 to 0f89d07 Compare December 2, 2022 08:05
@Linkerist
Copy link
Contributor Author

run starrocks_be_unittest

@github-actions
Copy link

github-actions bot commented Dec 2, 2022

clang-tidy review says "All clean, LGTM! 👍"

decster
decster previously approved these changes Dec 5, 2022
@sonarcloud
Copy link

sonarcloud bot commented Dec 7, 2022

Kudos, SonarCloud Quality Gate passed!    Quality Gate passed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 1 Code Smell

0.0% 0.0% Coverage
1.3% 1.3% Duplication

@wanpengfei-git
Copy link
Collaborator

[FE PR Coverage Check]

😞 fail : 13 / 43 (30.23%)

file detail

path covered_line new_line coverage not_covered_line_detail
🔵 com/starrocks/alter/SchemaChangeHandler.java 9 35 25.71% [504, 505, 507, 508, 509, 510, 513, 514, 518, 520, 1044, 1045, 1049, 1052, 1053, 1054, 1055, 1056, 1057, 1059, 1060, 1061, 1063, 1064, 1065, 1212]
🔵 com/starrocks/alter/SchemaChangeJobV2.java 2 6 33.33% [201, 314, 315, 316]
🔵 com/starrocks/alter/AlterJobV2Builder.java 2 2 100.00% []

@github-actions
Copy link

github-actions bot commented Dec 7, 2022

clang-tidy review says "All clean, LGTM! 👍"

@chaoyli chaoyli enabled auto-merge (squash) December 8, 2022 03:20
@wanpengfei-git wanpengfei-git added the Approved Ready to merge label Dec 8, 2022
@wanpengfei-git
Copy link
Collaborator

run starrocks_admit_test

@chaoyli chaoyli merged commit d25e71b into StarRocks:main Dec 8, 2022
@github-actions github-actions bot removed Approved Ready to merge be-build labels Dec 8, 2022
@sonarcloud
Copy link

sonarcloud bot commented Dec 8, 2022

Kudos, SonarCloud Quality Gate passed!    Quality Gate passed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 0 Code Smells

No Coverage information No Coverage information
2.2% 2.2% Duplication

@github-actions
Copy link

github-actions bot commented Dec 8, 2022

clang-tidy review says "All clean, LGTM! 👍"

@Linkerist Linkerist deleted the feature_support_schema_change_reorder_primary_key_model_sort_key branch December 8, 2022 05:15
Linkerist added a commit to Linkerist/starrocks that referenced this pull request Dec 8, 2022
… 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)
```
decster pushed a commit that referenced this pull request Dec 8, 2022
…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.
mergify bot pushed a commit that referenced this pull request Dec 13, 2022
…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
@mergify
Copy link
Contributor

mergify bot commented Dec 13, 2022

backport branch-2.5

✅ Backports have been created

decster pushed a commit that referenced this pull request Mar 28, 2023
…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]>
mergify bot pushed a commit that referenced this pull request Mar 28, 2023
…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)
mergify bot pushed a commit that referenced this pull request Mar 28, 2023
…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)
wanpengfei-git pushed a commit that referenced this pull request Mar 29, 2023
…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)
numbernumberone pushed a commit to numbernumberone/starrocks that referenced this pull request May 31, 2023
…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]>
abc982627271 pushed a commit to abc982627271/starrocks that referenced this pull request Jun 5, 2023
…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]>
sevev added a commit to sevev/starrocks that referenced this pull request Dec 7, 2023
…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]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Feature] Support schema change primary key model sort key.
4 participants