be/src/storage/index/index_query_context.h
Line | Count | Source |
1 | | // Licensed to the Apache Software Foundation (ASF) under one |
2 | | // or more contributor license agreements. See the NOTICE file |
3 | | // distributed with this work for additional information |
4 | | // regarding copyright ownership. The ASF licenses this file |
5 | | // to you under the Apache License, Version 2.0 (the |
6 | | // "License"); you may not use this file except in compliance |
7 | | // with the License. You may obtain a copy of the License at |
8 | | // |
9 | | // http://www.apache.org/licenses/LICENSE-2.0 |
10 | | // |
11 | | // Unless required by applicable law or agreed to in writing, |
12 | | // software distributed under the License is distributed on an |
13 | | // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
14 | | // KIND, either express or implied. See the License for the |
15 | | // specific language governing permissions and limitations |
16 | | // under the License. |
17 | | |
18 | | #pragma once |
19 | | |
20 | | #include <memory> |
21 | | #include <roaring/roaring.hh> |
22 | | |
23 | | #include "storage/compaction/collection_similarity.h" |
24 | | #include "storage/index/inverted/similarity/collection_statistics.h" |
25 | | |
26 | | namespace doris::segment_v2 { |
27 | | |
28 | | struct IndexQueryContext { |
29 | | io::IOContext* io_ctx = nullptr; |
30 | | OlapReaderStatistics* stats = nullptr; |
31 | | RuntimeState* runtime_state = nullptr; |
32 | | |
33 | | CollectionStatisticsPtr collection_statistics; |
34 | | CollectionSimilarityPtr collection_similarity; |
35 | | std::shared_ptr<const roaring::Roaring> delete_bitmap; |
36 | | |
37 | | size_t query_limit = 0; |
38 | | bool is_asc = false; |
39 | | |
40 | | // G02 count-only fast-path handshake. Set by SegmentIterator ONLY while it |
41 | | // evaluates the single pushed-down MATCH predicate of a COUNT_ON_INDEX scan |
42 | | // whose row space is provably unfiltered (no deletes, no other conjuncts, |
43 | | // full row bitmap, no row-id consumers -- see count_on_index_fastpath.h), |
44 | | // and reset immediately after. When set, an index reader MAY answer the |
45 | | // query with a bitmap whose CARDINALITY equals the match count without the |
46 | | // row ids being real (SNII returns [0, df) straight from dict-entry df, |
47 | | // skipping the posting decode). Readers must never cache such a bitmap |
48 | | // under a key a row-accurate query could hit. |
49 | | bool count_on_index_fastpath = false; |
50 | | |
51 | | // ---- Reply direction: fields a READER writes and the CALLER reads back ---- |
52 | | // |
53 | | // A caller that hands a reader a COPY of this context rather than the context itself must |
54 | | // fold the copy back with merge_reader_outputs(), or the reader's reply is dropped in |
55 | | // silence: nothing fails to compile, no test goes red, the query simply takes the wrong plan. |
56 | | // FunctionSearch's SNII leaf builder is such a caller -- it copies the context so the reader |
57 | | // publishes its BM25 into a throwaway CollectionSimilarity instead of the query's own. |
58 | | // |
59 | | // Every field added below this line must also be merged in merge_reader_outputs(). |
60 | | |
61 | | // G03 reply direction of the same handshake. Set by a reader iff it DID |
62 | | // answer with such a fabricated count bitmap (never on a query-cache hit, |
63 | | // a single-flight shared result, or any row-accurate decode). Read and |
64 | | // reset by SegmentIterator right after the index apply; a true value is |
65 | | // the precondition for the count-emission shortcut that materializes the |
66 | | // remaining count as default rows without iterating the row bitmap. |
67 | | bool count_on_index_fastpath_hit = false; |
68 | | |
69 | | // Folds the reply-direction fields a reader wrote on a copy of this context back into it. |
70 | | // Latching (never clearing) is what makes this safe to call for each of several readers. |
71 | 4 | void merge_reader_outputs(const IndexQueryContext& reader_context) { |
72 | 4 | count_on_index_fastpath_hit |= reader_context.count_on_index_fastpath_hit; |
73 | 4 | } |
74 | | }; |
75 | | using IndexQueryContextPtr = std::shared_ptr<IndexQueryContext>; |
76 | | |
77 | | } // namespace doris::segment_v2 |