-
Notifications
You must be signed in to change notification settings - Fork 49
feat: optimize count(*) for pk/append table #317
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
21 commits
Select commit
Hold shift + click to select a range
2fb3e38
feat: optimize count(*) for pk table
lucasfang 301ee99
fix
lucasfang af9a8a3
fix
lucasfang 4ddd426
fix
lucasfang 92ee56c
fix
lucasfang 014a1e7
fix
lucasfang 1cf7f98
fix
lucasfang 4692388
fix
lucasfang 3603cff
fix
lucasfang 4c37664
fix
lucasfang d30b59d
update merge row count & support data evolution merge row count
lucasfang cea2833
fix
lucasfang 833fb94
fix
lucasfang c2210fe
fix
lucasfang b3a9ad9
fix
lucasfang 841ea2b
fix
lucasfang 650bebf
fix
lucasfang 20db8db
fix
lucasfang b3da46c
fix
lucasfang 1751ac8
fix
lucasfang 01e7f6a
fix
lucasfang File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,33 @@ | ||
| /* | ||
| * Copyright 2026-present Alibaba Inc. | ||
| * | ||
| * Licensed under the Apache License, Version 2.0 (the "License"); | ||
| * you may not use this file except in compliance with the License. | ||
| * You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| */ | ||
|
|
||
| #pragma once | ||
|
|
||
| #include "paimon/result.h" | ||
| #include "paimon/visibility.h" | ||
|
|
||
| namespace paimon { | ||
|
|
||
| /// Reader abstraction for count queries. | ||
| class PAIMON_EXPORT CountReader { | ||
| public: | ||
| virtual ~CountReader() = default; | ||
|
|
||
| /// Count rows for splits bound by the corresponding CreateCountReader call. | ||
| virtual Result<int64_t> CountRows() = 0; | ||
| }; | ||
|
|
||
| } // namespace paimon | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,66 @@ | ||
| /* | ||
| * Copyright 2026-present Alibaba Inc. | ||
| * | ||
| * Licensed under the Apache License, Version 2.0 (the "License"); | ||
| * you may not use this file except in compliance with the License. | ||
| * You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| */ | ||
|
|
||
| #include "paimon/core/mergetree/row_count_accumulator.h" | ||
|
|
||
| #include <utility> | ||
|
|
||
| #include "paimon/core/key_value.h" | ||
|
|
||
| namespace paimon { | ||
|
|
||
| RowCountAccumulator::RowCountAccumulator(std::unique_ptr<SortMergeReader>&& merged_reader) | ||
| : merged_reader_(std::move(merged_reader)) {} | ||
|
|
||
| Result<int64_t> RowCountAccumulator::CountAll() { | ||
| int64_t count = 0; | ||
|
|
||
| while (true) { | ||
| // Get next batch of merged KV iterators | ||
| PAIMON_ASSIGN_OR_RAISE(std::unique_ptr<SortMergeReader::Iterator> iter, | ||
| merged_reader_->NextBatch()); | ||
| if (iter == nullptr) { | ||
| // No more data | ||
| break; | ||
| } | ||
|
|
||
| // Iterate through all KV objects in this batch | ||
| while (true) { | ||
| PAIMON_ASSIGN_OR_RAISE(bool has_next, iter->HasNext()); | ||
| if (!has_next) { | ||
| break; | ||
| } | ||
|
|
||
| iter->Next(); | ||
|
|
||
| // At this point: | ||
| // - kv has passed through SortMergeReader (deduplicated, merged) | ||
| // - kv has passed through DropDeleteReader (kind is guaranteed IsAdd()) | ||
| // - kv represents a final, valid, non-deleted row | ||
| count++; | ||
| } | ||
| } | ||
|
|
||
| return count; | ||
| } | ||
|
|
||
| void RowCountAccumulator::Close() { | ||
| if (merged_reader_) { | ||
| merged_reader_->Close(); | ||
| } | ||
| } | ||
|
|
||
| } // namespace paimon |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,47 @@ | ||
| /* | ||
| * Copyright 2026-present Alibaba Inc. | ||
| * | ||
| * Licensed under the Apache License, Version 2.0 (the "License"); | ||
| * you may not use this file except in compliance with the License. | ||
| * You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| */ | ||
|
|
||
| #pragma once | ||
|
|
||
| #include <cstdint> | ||
| #include <memory> | ||
|
|
||
| #include "paimon/core/mergetree/compact/sort_merge_reader.h" | ||
| #include "paimon/result.h" | ||
|
|
||
| namespace paimon { | ||
|
|
||
| /// Counts rows from a merged KeyValue stream after delete rows are dropped. | ||
| class RowCountAccumulator { | ||
| public: | ||
| /// @param merged_reader The merged reader. Must be wrapped with DropDeleteReader | ||
| /// so that only valid (non-deleted) KeyValue objects are output. | ||
| explicit RowCountAccumulator(std::unique_ptr<SortMergeReader>&& merged_reader); | ||
|
|
||
| ~RowCountAccumulator() = default; | ||
|
|
||
| /// Count all valid rows from the merge reader. | ||
| /// Iterates through all merged+deduplicated+non-deleted KeyValue objects. | ||
| Result<int64_t> CountAll(); | ||
|
|
||
| /// Close underlying readers and release resources. | ||
| void Close(); | ||
|
|
||
| private: | ||
| std::unique_ptr<SortMergeReader> merged_reader_; | ||
| }; | ||
|
|
||
| } // namespace paimon |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.