Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 35 additions & 2 deletions be/src/olap/schema_change.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1859,6 +1859,29 @@ OLAPStatus SchemaChangeHandler::_parse_request(TabletSharedPtr base_tablet,
// 若Key列的引用序列出现乱序,则需要重排序
int num_default_value = 0;

// A, B, C are keys(sort keys), D is value
// The following cases are not changing the order, no need to resort:
// (sort keys keep in same order)
// old keys: A B C D
// new keys: A X B C D
//
// old keys: A B C D
// new keys: X A B C D
//
// old keys: A B C D
// new keys: A B C
//
// old keys: A B C D
// new keys: A B
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

After this pull request.
old keys: A B C D
new keys: A B C
will be resorted.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry that this PR is not ready, I will consider more situation.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This case also need be re-agg, so the sc_sorting must be marked as true.

//
// followings need resort:
// (sort keys' order is changed)
// old keys: A B C D
// new keys: B C A
//
// old keys: A B C D
// new keys: A C D
//
for (int i = 0, new_schema_size = new_tablet->num_key_columns();
i < new_schema_size; ++i) {
ColumnMapping* column_mapping = rb_changer->get_mutable_column_mapping(i);
Expand All @@ -1874,14 +1897,24 @@ OLAPStatus SchemaChangeHandler::_parse_request(TabletSharedPtr base_tablet,
}
}

// goes here, the sort keys are keep in origin order.
const TabletSchema& ref_tablet_schema = base_tablet->tablet_schema();
const TabletSchema& new_tablet_schema = new_tablet->tablet_schema();
if (new_tablet_schema.keys_type() != KeysType::DUP_KEYS
&& new_tablet->num_key_columns() < base_tablet->num_key_columns()) {
// this is a table with aggregate key type, and num of key columns in new schema
// is less, which means the data in new tablet should be more aggregated.
// so we use sorting schema change to sort and merge the data.
*sc_sorting = true;
return OLAP_SUCCESS;
}

if (base_tablet->num_short_key_columns() != new_tablet->num_short_key_columns()) {
// the number of short_keys changed, can't do linked schema change
*sc_directly = true;
return OLAP_SUCCESS;
}

const TabletSchema& ref_tablet_schema = base_tablet->tablet_schema();
const TabletSchema& new_tablet_schema = new_tablet->tablet_schema();
for (size_t i = 0; i < new_tablet->num_columns(); ++i) {
ColumnMapping* column_mapping = rb_changer->get_mutable_column_mapping(i);
if (column_mapping->ref_column < 0) {
Expand Down