|
26 | 26 | #include <algorithm> |
27 | 27 | #include <cstring> |
28 | 28 | #include <memory> |
| 29 | +#include <optional> |
29 | 30 | #include <set> |
30 | 31 | #include <utility> |
31 | 32 |
|
|
67 | 68 | #include "storage/olap_common.h" |
68 | 69 | #include "storage/predicate/block_column_predicate.h" |
69 | 70 | #include "storage/predicate/column_predicate.h" |
| 71 | +#include "storage/read_time_hidden_column.h" |
70 | 72 | #include "storage/rowset/rowset_reader_context.h" |
71 | 73 | #include "storage/schema.h" |
72 | 74 | #include "storage/segment/column_meta_accessor.h" |
@@ -1026,57 +1028,25 @@ Status Segment::_get_column_reader_for_read(const TabletColumn& col, |
1026 | 1028 | RETURN_IF_ERROR(_create_column_meta_once(read_options.stats, &read_options.io_ctx)); |
1027 | 1029 | SCOPED_RAW_TIMER(&read_options.stats->segment_create_column_readers_timer_ns); |
1028 | 1030 |
|
1029 | | - if (col.name() == VERSION_COL) { |
1030 | | - // A singleton rowset exposes its rowset version for every row. Segment writers store a |
1031 | | - // placeholder because the publish version is not known when the segment is written. |
1032 | | - if (read_options.version.first == read_options.version.second) { |
1033 | | - *column_reader = std::make_shared<ConstantColumnReader>( |
1034 | | - Field::create_field<TYPE_BIGINT>(read_options.version.second), col.type()); |
| 1031 | + // Read-time hidden columns use the resolution policy shared with direct reads; anything else |
| 1032 | + // falls through to the stored column below. |
| 1033 | + const ReadTimeHiddenColumnType hidden_column_type = get_read_time_hidden_column_type(col); |
| 1034 | + if (hidden_column_type != ReadTimeHiddenColumnType::NONE) { |
| 1035 | + std::optional<Field> constant_value; |
| 1036 | + RETURN_IF_ERROR( |
| 1037 | + resolve_read_time_hidden_column_value(hidden_column_type, read_options.version, |
| 1038 | + read_options.commit_tso, &constant_value)); |
| 1039 | + if (constant_value.has_value()) { |
| 1040 | + *column_reader = |
| 1041 | + std::make_shared<ConstantColumnReader>(std::move(*constant_value), col.type()); |
1035 | 1042 | return Status::OK(); |
1036 | 1043 | } |
1037 | 1044 | if (!_column_meta_accessor->has_column_uid(col_uid)) { |
1038 | | - return Status::InternalError("could not find version column read version is {}-{}", |
1039 | | - read_options.version.first, read_options.version.second); |
1040 | | - } |
1041 | | - return _column_reader_cache->get_column_reader(col_uid, column_reader, read_options.stats, |
1042 | | - &read_options.io_ctx); |
1043 | | - } |
1044 | | - |
1045 | | - if (col.name() == BINLOG_TSO_COL || col.name() == COMMIT_TSO_COL) { |
1046 | | - const int64_t start_tso = read_options.commit_tso.start_tso(); |
1047 | | - const int64_t end_tso = read_options.commit_tso.end_tso(); |
1048 | | - // Version [0-0] identifies a pre-publish physical read, such as segment compaction while a |
1049 | | - // RowsetWriter is still open. Its TSO is intentionally [-1--1], so preserve the on-disk |
1050 | | - // COMMIT_TSO_COL=0 or BINLOG_TSO_COL=NULL placeholder instead of synthesizing a value. |
1051 | | - if (read_options.version == Version(0, 0) && start_tso == -1 && end_tso == -1) { |
1052 | | - if (!_column_meta_accessor->has_column_uid(col_uid)) { |
1053 | | - return Status::InternalError("could not find {} column", col.name()); |
| 1045 | + if (hidden_column_type == ReadTimeHiddenColumnType::VERSION) { |
| 1046 | + return Status::InternalError("could not find version column read version is {}-{}", |
| 1047 | + read_options.version.first, |
| 1048 | + read_options.version.second); |
1054 | 1049 | } |
1055 | | - return _column_reader_cache->get_column_reader( |
1056 | | - col_uid, column_reader, read_options.stats, &read_options.io_ctx); |
1057 | | - } |
1058 | | - if (read_options.version.first == read_options.version.second) { |
1059 | | - // A singleton needs its publish TSO to replace the on-disk NULL/0 placeholder. |
1060 | | - // Range rowsets already contain materialized TSOs: compacting the initial empty |
1061 | | - // [0-1] rowset with [2-2] and [3-3] can leave a valid output with TSO range [-1, T3]. |
1062 | | - if (start_tso < 0 || end_tso < start_tso) { |
1063 | | - return Status::InternalError( |
1064 | | - "reading {} requires a valid commit tso, rowset version={}, commit tso={}", |
1065 | | - col.name(), read_options.version.to_string(), |
1066 | | - read_options.commit_tso.to_string()); |
1067 | | - } |
1068 | | - if (start_tso != end_tso) { |
1069 | | - return Status::InternalError( |
1070 | | - "singleton rowset {} requires a singleton commit tso when reading {}, " |
1071 | | - "got {}", |
1072 | | - read_options.version.to_string(), col.name(), |
1073 | | - read_options.commit_tso.to_string()); |
1074 | | - } |
1075 | | - *column_reader = std::make_shared<ConstantColumnReader>( |
1076 | | - Field::create_field<TYPE_BIGINT>(end_tso), col.type()); |
1077 | | - return Status::OK(); |
1078 | | - } |
1079 | | - if (!_column_meta_accessor->has_column_uid(col_uid)) { |
1080 | 1050 | return Status::InternalError("could not find {} column", col.name()); |
1081 | 1051 | } |
1082 | 1052 | return _column_reader_cache->get_column_reader(col_uid, column_reader, read_options.stats, |
|
0 commit comments