fix bug select from virtual table report -4201

This commit is contained in:
obdev
2023-08-10 07:18:31 +00:00
committed by ob-robot
parent 03cc2be4ea
commit d4c46975a8
2 changed files with 18 additions and 2 deletions

View File

@ -1075,9 +1075,19 @@ int ObAffinitizeGranuleSplitter::split_tasks_affinity(ObExecContext &ctx,
LOG_WARN("fail to build tablet idx map", K(ret)); LOG_WARN("fail to build tablet idx map", K(ret));
} }
} }
if (OB_FAIL(ret)) { if (OB_SUCC(ret)) {
// see issue
// for virtual table, we can directly mock a tablet id
// function build_tablet_idx_map will mock a idx map whose key
// varies from 1 to table_schema->get_all_part_num(), and the value = key + 1
// so we can directly set tablet_idx = tablet_loc.tablet_id_.id() + 1, the result is same
if (is_virtual_table(table_schema->get_table_id())) {
tablet_idx = tablet_loc.tablet_id_.id() + 1;
} else if (OB_FAIL(idx_map.get_refactored(tablet_loc.tablet_id_.id(), tablet_idx))) { } else if (OB_FAIL(idx_map.get_refactored(tablet_loc.tablet_id_.id(), tablet_idx))) {
LOG_WARN("fail to get tablet idx", K(ret)); LOG_WARN("fail to get tablet idx", K(ret));
}
}
if (OB_FAIL(ret)) {
} else if (OB_FAIL(ObPxAffinityByRandom::get_tablet_info(tablet_loc.tablet_id_.id(), } else if (OB_FAIL(ObPxAffinityByRandom::get_tablet_info(tablet_loc.tablet_id_.id(),
partitions_info_, partitions_info_,
partition_row_info))) { partition_row_info))) {

View File

@ -1450,6 +1450,12 @@ int ObPXServerAddrUtil::build_tablet_idx_map(
} else if (OB_FAIL(idx_map.create(table_schema->get_all_part_num(), "TabletOrderIdx"))) { } else if (OB_FAIL(idx_map.create(table_schema->get_all_part_num(), "TabletOrderIdx"))) {
LOG_WARN("fail create index map", K(ret), "cnt", table_schema->get_all_part_num()); LOG_WARN("fail create index map", K(ret), "cnt", table_schema->get_all_part_num());
} else if (is_virtual_table(table_schema->get_table_id())) { } else if (is_virtual_table(table_schema->get_table_id())) {
// In observer 4.2, the table schema of a distributed virtual table will show all_part_num as 1,
// whereas in lower versions it would display as 65536.
// For a distrubuted virtual table, we may encounter a situation where part_id is 1 in sqc1,
// part_id is 2 in sqc2 and so on, but the idx_map only contains one item with key=1.
// Hence, if we seek with part_id=2, the idx_map will return -4201 (OB_HASH_NOT_EXIST)
// will return -4201(OB_HASH_NOT_EXIST). In such cases, we can directly obtain the value that equals part_id + 1.
for (int i = 0; OB_SUCC(ret) && i < table_schema->get_all_part_num(); ++i) { for (int i = 0; OB_SUCC(ret) && i < table_schema->get_all_part_num(); ++i) {
if (OB_FAIL(idx_map.set_refactored(i + 1, tablet_idx++))) { if (OB_FAIL(idx_map.set_refactored(i + 1, tablet_idx++))) {
LOG_WARN("fail set value to hashmap", K(ret)); LOG_WARN("fail set value to hashmap", K(ret));