From ea1fc6cf80c26c43344fba8c7d2d74812d761ba3 Mon Sep 17 00:00:00 2001 From: ZhangYu0123 Date: Thu, 3 Sep 2020 10:31:17 +0800 Subject: [PATCH 1/4] fix --- be/src/olap/rowset/segment_group.cpp | 35 +++++++++++++++++++--------- 1 file changed, 24 insertions(+), 11 deletions(-) diff --git a/be/src/olap/rowset/segment_group.cpp b/be/src/olap/rowset/segment_group.cpp index eff48c0b5162ef..fcbd2ef43aec0c 100644 --- a/be/src/olap/rowset/segment_group.cpp +++ b/be/src/olap/rowset/segment_group.cpp @@ -258,32 +258,45 @@ OLAPStatus SegmentGroup::add_zone_maps_for_linked_schema_change( for (size_t i = 0; i < zonemap_col_num; ++i) { - // in duplicated table update from 0.11 to 0.12, zone map index may be missed + // in duplicated table update from 0.11 to 0.12, zone map index may be missed and may not a new column. if (_schema->keys_type() == DUP_KEYS && schema_mapping[i].ref_column != -1 && schema_mapping[i].ref_column >= zone_map_fields.size()) { - continue; + break; // _zone_maps follows _schema column index } const TabletColumn& column = _schema->column(i); - WrapperField* first = WrapperField::create(column); - DCHECK(first != NULL) << "failed to allocate memory for field: " << i; - - WrapperField* second = WrapperField::create(column); - DCHECK(second != NULL) << "failed to allocate memory for field: " << i; + // nullptr is checked in olap_cond.cpp eval, note: When we apply column statistic, Field can be NULL when type is Varchar. + WrapperField* first = nullptr; + WrapperField* second = nullptr; // when this is no ref_column (add new column), fill default value if (schema_mapping[i].ref_column == -1 || schema_mapping[i].ref_column >= zone_map_fields.size()) { // ref_column == -1 means this is a new column. // for new column, use default value to fill into column_statistics if (schema_mapping[i].default_value != nullptr) { + first = WrapperField::create(column); + DCHECK(first != nullptr) << "failed to allocate memory for field: " << i; first->copy(schema_mapping[i].default_value); + second = WrapperField::create(column); + DCHECK(second != nullptr) << "failed to allocate memory for field: " << i; second->copy(schema_mapping[i].default_value); - } + } } else { - // use src column's zone map value to fill - first->copy(zone_map_fields[schema_mapping[i].ref_column].first); - second->copy(zone_map_fields[schema_mapping[i].ref_column].second); + WrapperField* wfirst = zone_map_fields[schema_mapping[i].ref_column].first; + WrapperField* wsecond = zone_map_fields[schema_mapping[i].ref_column].second; + + if (wfirst != nullptr) { + first = WrapperField::create(column); + DCHECK(first != nullptr) << "failed to allocate memory for field: " << i; + first->copy(wfirst); + } + + if (wsecond != nullptr) { + second = WrapperField::create(column); + DCHECK(second != nullptr) << "failed to allocate memory for field: " << i; + second->copy(wsecond); + } } _zone_maps.push_back(std::make_pair(first, second)); From 20417fa74260f54b192b2149627ca94be5a189a9 Mon Sep 17 00:00:00 2001 From: ZhangYu0123 Date: Thu, 3 Sep 2020 16:46:24 +0800 Subject: [PATCH 2/4] add comment --- be/src/olap/rowset/segment_group.cpp | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/be/src/olap/rowset/segment_group.cpp b/be/src/olap/rowset/segment_group.cpp index fcbd2ef43aec0c..2f628163bc75c4 100644 --- a/be/src/olap/rowset/segment_group.cpp +++ b/be/src/olap/rowset/segment_group.cpp @@ -262,7 +262,10 @@ OLAPStatus SegmentGroup::add_zone_maps_for_linked_schema_change( if (_schema->keys_type() == DUP_KEYS && schema_mapping[i].ref_column != -1 && schema_mapping[i].ref_column >= zone_map_fields.size()) { - break; // _zone_maps follows _schema column index + + // the sequence of columns in _zone_maps and _schema must be consistent, so here + // should not this column missed zonemap and we break the loap. + break; } const TabletColumn& column = _schema->column(i); @@ -299,6 +302,8 @@ OLAPStatus SegmentGroup::add_zone_maps_for_linked_schema_change( } } + // first and second can be nullptr, because when type is Varchar then default_value and zone_map_fields in old column + // can be nullptr, and it is checked in olap_cond.cpp eval function. _zone_maps.push_back(std::make_pair(first, second)); } From 7643afcd4fcbb733dcdcfa4de7c2540410fcb474 Mon Sep 17 00:00:00 2001 From: ZhangYu0123 Date: Thu, 3 Sep 2020 16:49:21 +0800 Subject: [PATCH 3/4] add comment --- be/src/olap/rowset/segment_group.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/be/src/olap/rowset/segment_group.cpp b/be/src/olap/rowset/segment_group.cpp index 2f628163bc75c4..b708c5c04ddf17 100644 --- a/be/src/olap/rowset/segment_group.cpp +++ b/be/src/olap/rowset/segment_group.cpp @@ -264,7 +264,7 @@ OLAPStatus SegmentGroup::add_zone_maps_for_linked_schema_change( schema_mapping[i].ref_column >= zone_map_fields.size()) { // the sequence of columns in _zone_maps and _schema must be consistent, so here - // should not this column missed zonemap and we break the loap. + // process should not add missed zonemap and we break the loap. break; } const TabletColumn& column = _schema->column(i); From 630ece527b6f208bb965cd4a574d140874b941c7 Mon Sep 17 00:00:00 2001 From: ZhangYu0123 <67053339+ZhangYu0123@users.noreply.github.com> Date: Thu, 3 Sep 2020 17:11:27 +0800 Subject: [PATCH 4/4] Update be/src/olap/rowset/segment_group.cpp Co-authored-by: Mingyu Chen --- be/src/olap/rowset/segment_group.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/be/src/olap/rowset/segment_group.cpp b/be/src/olap/rowset/segment_group.cpp index b708c5c04ddf17..11f9abffb96138 100644 --- a/be/src/olap/rowset/segment_group.cpp +++ b/be/src/olap/rowset/segment_group.cpp @@ -264,7 +264,7 @@ OLAPStatus SegmentGroup::add_zone_maps_for_linked_schema_change( schema_mapping[i].ref_column >= zone_map_fields.size()) { // the sequence of columns in _zone_maps and _schema must be consistent, so here - // process should not add missed zonemap and we break the loap. + // process should not add missed zonemap and we break the loop. break; } const TabletColumn& column = _schema->column(i);