-
Notifications
You must be signed in to change notification settings - Fork 22
feat(core): read source-backed primary-key BTree indexes #194
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
base: main
Are you sure you want to change the base?
Changes from all commits
6cadf2a
2995d6f
e90b5d6
4fa5817
a477bfb
d5990c9
e0c09a2
a507f43
48bf6b7
1469b2e
a948512
b02dd5f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -42,3 +42,4 @@ User Guide | |
| user_guide/prefetch | ||
| user_guide/arrow | ||
| user_guide/global_index | ||
| user_guide/primary_key_global_index | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,73 @@ | ||
| .. Licensed to the Apache Software Foundation (ASF) under one | ||
| .. or more contributor license agreements. See the NOTICE file | ||
| .. distributed with this work for additional information | ||
| .. regarding copyright ownership. The ASF licenses this file | ||
| .. to you 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. | ||
|
|
||
| Primary Key Global Index | ||
| ======================== | ||
|
|
||
| Paimon 2.0 primary-key tables support *source-backed* global scalar indexes | ||
| (``pk-btree`` / ``pk-bitmap``). Unlike the Data Evolution global indexes described in | ||
| :doc:`global_index`, which address rows by a table-wide row id, a source-backed payload | ||
| covers the complete active source set of one positive data level of one bucket, and its | ||
| results are group ordinals that are localized back to per-file physical row positions. | ||
|
|
||
| paimon-cpp supports the read path of this protocol: ordinary batch scans of a | ||
| primary-key table with scalar index definitions automatically evaluate the part of the | ||
| scan predicate that touches indexed fields against the validated payload groups of the | ||
| scanned snapshot, and narrow covered files to indexed splits carrying file-local row | ||
| ranges. No dedicated query API is required. | ||
|
|
||
| Table requirements | ||
| ------------------ | ||
|
|
||
| The definitions follow the Java table options: | ||
|
|
||
| - ``'pk-btree.index.columns' = 'price'`` with optional | ||
| ``'fields.price.pk-btree.index.options' = '{"block-size":"64 kb"}'`` | ||
| - fixed bucket (``bucket > 0``) or postpone bucket mode | ||
| - ``'deletion-vectors.enabled' = 'true'`` and ``'deletion-vectors.merge-on-read' = 'false'`` | ||
|
|
||
| Semantics | ||
| --------- | ||
|
|
||
| - A payload is only used when it provably covers the current active source set of its | ||
| data level: exactly one payload per level, source file names / order / row counts | ||
| identical to the active COMPACT files of that level, matching index type and field id, | ||
| and a row range of exactly ``[0, total source rows - 1]``. Anything else is treated as | ||
| uncovered and scanned normally. | ||
| - ``AND`` predicates narrow with any safely evaluable indexed child; ``OR`` predicates | ||
| only use the index when every branch is evaluable. Files whose evaluation fails, whose | ||
| positions are out of range, or whose result needs more than 4096 ranges fall back to a | ||
| normal scan individually. | ||
| - Indexed splits keep their deletion files aligned with the data file; the reader still | ||
| applies deletion vectors and the complete original predicate, so index results never | ||
| change visibility semantics. | ||
| - ``'global-index.enabled' = 'false'`` disables the planner. | ||
|
|
||
| Current scope | ||
| ------------- | ||
|
|
||
| - The BTree payload reader is wired up. ``pk-bitmap`` (and vector / full-text) | ||
| definitions are recognized for validation, but their evaluation conservatively falls | ||
| back to a normal scan until their dedicated payload readers are supported. | ||
| - The read path targets the Java release-2.0.0 layout and scan semantics (source metadata | ||
| v1, ``GlobalIndexMeta`` with ``_SOURCE_META``, commit message v12). Source-file names | ||
| currently use the existing C++ length-prefixed UTF-8 streams; ASCII and non-null BMP | ||
| names are compatible with Java ``writeUTF``, while complete modified UTF-8 support for | ||
| supplementary code points will be handled by a shared stream-level change. | ||
| - ``PkSortedIndexFile::Build`` can build one payload for an ordered source group from | ||
| value-sorted input, which supports tooling and tests; automatic build and maintenance | ||
| during compaction is not included yet. |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,75 @@ | ||
| /* | ||
| * Licensed to the Apache Software Foundation (ASF) under one | ||
| * or more contributor license agreements. See the NOTICE file | ||
| * distributed with this work for additional information | ||
| * regarding copyright ownership. The ASF licenses this file | ||
| * to you 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 <map> | ||
| #include <string> | ||
| #include <utility> | ||
|
|
||
| namespace paimon { | ||
| /// Resolved definition of one source-backed primary-key index. | ||
| class PrimaryKeyIndexDefinition { | ||
| public: | ||
| /// Built-in primary-key index families. | ||
| enum class Family { | ||
| VECTOR, | ||
| BTREE, | ||
| BITMAP, | ||
| FULL_TEXT, | ||
| }; | ||
|
|
||
| PrimaryKeyIndexDefinition(std::string column, int32_t field_id, std::string index_type, | ||
| Family family, std::map<std::string, std::string> options) | ||
| : column_(std::move(column)), | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Could we move the
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Updated. |
||
| field_id_(field_id), | ||
| index_type_(std::move(index_type)), | ||
| family_(family), | ||
| options_(std::move(options)) {} | ||
|
|
||
| const std::string& Column() const { | ||
| return column_; | ||
| } | ||
|
|
||
| int32_t FieldId() const { | ||
| return field_id_; | ||
| } | ||
|
|
||
| const std::string& IndexType() const { | ||
| return index_type_; | ||
| } | ||
|
|
||
| Family GetFamily() const { | ||
| return family_; | ||
| } | ||
|
|
||
| const std::map<std::string, std::string>& Options() const { | ||
| return options_; | ||
| } | ||
|
|
||
| private: | ||
| std::string column_; | ||
| int32_t field_id_; | ||
| std::string index_type_; | ||
| Family family_; | ||
| std::map<std::string, std::string> options_; | ||
| }; | ||
|
|
||
| } // namespace paimon | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@lszskye Please evaluate whether using
GlobalDefaultExecutorhere could cause any issues. I’d lean toward passing the same executor to each reader instead.Also, the executor thread count in Java is based on
GLOBAL_INDEX_THREAD_NUM, rather than using the machine core count asGetGlobalDefaultExecutor()does.A more complete approach would be to let
C++ GlobalIndexer:accept an external executor and, like Java, have the scan layer create and pass it in based onglobal-index.thread-num, instead of havingBTreeGlobalIndexerimplicitly chooseGetGlobalDefaultExecutor().There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Updated.
GlobalIndexer::CreateReadernow accepts an external executor.PrimaryKeyIndexBatchScancreates one scan-scoped executor fromglobal-index.thread-numand shares it across BTree readers; when unset, it preserves the existing C++ CPU-count default. The legacyGlobalIndexScanImplpath keeps its outer executor separate to avoid nested synchronous work on the same fixed-size pool. No executor is created when the plan has no valid index group.