aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorivanmorozov <ivanmorozov@yandex-team.com>2023-05-17 19:27:35 +0300
committerivanmorozov <ivanmorozov@yandex-team.com>2023-05-17 19:27:35 +0300
commitb55144147cefdad61b07aab04654120f63ce1a0a (patch)
tree2cb23549ac3399916ee60c4e519d19f7357bde68
parent9d71f1560dec58f4eb2b12bbc239933fb1ca44ba (diff)
downloadydb-b55144147cefdad61b07aab04654120f63ce1a0a.tar.gz
use indexkey data for full pk usage in future
switch off optimization for non-full-pk indexkey
-rw-r--r--ydb/core/tx/columnshard/engines/reader/batch.cpp54
-rw-r--r--ydb/core/tx/columnshard/engines/reader/read_metadata.cpp3
2 files changed, 21 insertions, 36 deletions
diff --git a/ydb/core/tx/columnshard/engines/reader/batch.cpp b/ydb/core/tx/columnshard/engines/reader/batch.cpp
index f66481c1d0d..fcbcb40169d 100644
--- a/ydb/core/tx/columnshard/engines/reader/batch.cpp
+++ b/ydb/core/tx/columnshard/engines/reader/batch.cpp
@@ -30,11 +30,12 @@ NColumnShard::IDataTasksProcessor::ITask::TPtr TBatch::AssembleTask(NColumnShard
Y_VERIFY(!FetchedInfo.GetFilteredBatch());
auto blobSchema = readMetadata->GetLoadSchema(PortionInfo->GetSnapshot());
+ auto readSchema = readMetadata->GetLoadSchema(readMetadata->GetSnapshot());
ISnapshotSchema::TPtr resultSchema;
if (CurrentColumnIds) {
- resultSchema= std::make_shared<TFilteredSnapshotSchema>(readMetadata->GetLoadSchema(readMetadata->GetSnapshot()), *CurrentColumnIds);
+ resultSchema = std::make_shared<TFilteredSnapshotSchema>(readSchema, *CurrentColumnIds);
} else {
- resultSchema = readMetadata->GetLoadSchema(readMetadata->GetSnapshot());
+ resultSchema = readSchema;
}
auto batchConstructor = PortionInfo->PrepareForAssemble(*blobSchema, *resultSchema, Data);
Data.clear();
@@ -184,39 +185,22 @@ std::shared_ptr<TSortableBatchPosition> TBatch::GetFirstPK(const bool reverse, c
}
void TBatch::GetPKBorders(const bool reverse, const TIndexInfo& indexInfo, std::shared_ptr<TSortableBatchPosition>& from, std::shared_ptr<TSortableBatchPosition>& to) const {
- from = nullptr;
- to = nullptr;
- if (!FirstPK || !LastPK) {
- std::vector<std::shared_ptr<arrow::Scalar>> minRecord;
- std::vector<std::shared_ptr<arrow::Scalar>> maxRecord;
- for (auto&& i : indexInfo.GetReplaceKey()->fields()) {
- const ui32 columnId = indexInfo.GetColumnId(i->name());
- const auto& [minScalar, maxScalar] = PortionInfo->MinMaxValue(columnId);
- if (!FirstPK && !minScalar) {
- FirstPK = nullptr;
- ReverseLastPK = nullptr;
- } else {
- minRecord.emplace_back(minScalar);
- }
- if (!LastPK && !maxScalar) {
- LastPK = nullptr;
- ReverseFirstPK = nullptr;
- } else {
- maxRecord.emplace_back(maxScalar);
- }
- }
- if (!FirstPK) {
- auto batch = NArrow::BuildSingleRecordBatch(indexInfo.GetReplaceKey(), minRecord);
- Y_VERIFY(batch);
- FirstPK = std::make_shared<TSortableBatchPosition>(batch, 0, indexInfo.GetReplaceKey()->field_names(), false);
- ReverseLastPK = std::make_shared<TSortableBatchPosition>(batch, 0, indexInfo.GetReplaceKey()->field_names(), true);
- }
- if (!LastPK) {
- auto batch = NArrow::BuildSingleRecordBatch(indexInfo.GetReplaceKey(), maxRecord);
- Y_VERIFY(batch);
- LastPK = std::make_shared<TSortableBatchPosition>(batch, 0, indexInfo.GetReplaceKey()->field_names(), false);
- ReverseFirstPK = std::make_shared<TSortableBatchPosition>(batch, 0, indexInfo.GetReplaceKey()->field_names(), true);
- }
+ auto indexKey = indexInfo.GetIndexKey();
+ if (!FirstPK) {
+ Y_VERIFY(PortionInfo->Valid());
+ const NArrow::TReplaceKey& minRecord = PortionInfo->IndexKeyStart();
+ auto batch = minRecord.ToBatch(indexKey);
+ Y_VERIFY(batch);
+ FirstPK = std::make_shared<TSortableBatchPosition>(batch, 0, indexKey->field_names(), false);
+ ReverseLastPK = std::make_shared<TSortableBatchPosition>(batch, 0, indexKey->field_names(), true);
+ }
+ if (!LastPK) {
+ Y_VERIFY(PortionInfo->Valid());
+ const NArrow::TReplaceKey& maxRecord = PortionInfo->IndexKeyEnd();
+ auto batch = maxRecord.ToBatch(indexKey);
+ Y_VERIFY(batch);
+ LastPK = std::make_shared<TSortableBatchPosition>(batch, 0, indexKey->field_names(), false);
+ ReverseFirstPK = std::make_shared<TSortableBatchPosition>(batch, 0, indexKey->field_names(), true);
}
if (reverse) {
from = *ReverseFirstPK;
diff --git a/ydb/core/tx/columnshard/engines/reader/read_metadata.cpp b/ydb/core/tx/columnshard/engines/reader/read_metadata.cpp
index da799734056..626eb64a46d 100644
--- a/ydb/core/tx/columnshard/engines/reader/read_metadata.cpp
+++ b/ydb/core/tx/columnshard/engines/reader/read_metadata.cpp
@@ -205,7 +205,8 @@ void TReadStats::PrintToLog() {
NIndexedReader::IOrderPolicy::TPtr TReadMetadata::BuildSortingPolicy() const {
auto& indexInfo = ResultIndexSchema->GetIndexInfo();
- if (Limit && IsSorted() && indexInfo.IsSorted() && indexInfo.GetSortingKey()->num_fields()) {
+ if (Limit && IsSorted() && indexInfo.IsSorted() && indexInfo.GetSortingKey()->num_fields() &&
+ indexInfo.GetReplaceKey()->Equals(indexInfo.GetIndexKey())) {
ui32 idx = 0;
for (auto&& i : indexInfo.GetPrimaryKey()) {
if (idx >= indexInfo.GetSortingKey()->fields().size()) {