From 4d872ae6bc98fc5b9e7d0e17eafad12e4031de90 Mon Sep 17 00:00:00 2001 From: emmymiao87 <522274284@qq.com> Date: Thu, 10 Sep 2020 20:19:37 +0800 Subject: [PATCH 1/2] [BUG] Reagg when adding agg mv on dup base table When the keystype of mv and base table is difference, Doris should execute sorting schema change instead of linked schema change. If doesn't, the data size of mv actually is same as base table. This will cause mv to have no pre-aggregation effect at all. The query will not choose mv. This commit fixed this problem. Fixed #4586 Change-Id: Ibe67a389235b716d260f600edf7a0f9d9d4242b4 --- be/src/olap/schema_change.cpp | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/be/src/olap/schema_change.cpp b/be/src/olap/schema_change.cpp index 3522b1b5fa1608..7e2bf02ae33f5b 100644 --- a/be/src/olap/schema_change.cpp +++ b/be/src/olap/schema_change.cpp @@ -2090,14 +2090,21 @@ OLAPStatus SchemaChangeHandler::_parse_request(TabletSharedPtr base_tablet, } } + const TabletSchema& ref_tablet_schema = base_tablet->tablet_schema(); + const TabletSchema& new_tablet_schema = new_tablet->tablet_schema(); + if (ref_tablet_schema.keys_type() != new_tablet_schema.keys_type()) { + // only when base table is dup and mv is agg + // the rollup job must be reagg. + *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) { From f7a11062e8df7b5c124a84d600e4d6ab456d39df Mon Sep 17 00:00:00 2001 From: emmymiao87 <522274284@qq.com> Date: Fri, 11 Sep 2020 18:21:05 +0800 Subject: [PATCH 2/2] Add another case Change-Id: Ib4b59f7cfe6e0e30d0740257e9bf073659807e88 --- be/src/olap/schema_change.cpp | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/be/src/olap/schema_change.cpp b/be/src/olap/schema_change.cpp index 7e2bf02ae33f5b..81ace25c7808cb 100644 --- a/be/src/olap/schema_change.cpp +++ b/be/src/olap/schema_change.cpp @@ -2099,6 +2099,22 @@ OLAPStatus SchemaChangeHandler::_parse_request(TabletSharedPtr base_tablet, return OLAP_SUCCESS; } + // If the sort of key has not been changed but the new keys num is less then base's, + // the new table should be re agg. + // So we also need to set sc_sorting = true. + // A, B, C are keys(sort keys), D is value + // followings need resort: + // old keys: A B C D + // new keys: A B + 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;