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 "storage/compaction/collection_similarity.h" |
21 | | #include "storage/index/inverted/similarity/collection_statistics.h" |
22 | | |
23 | | namespace doris::segment_v2 { |
24 | | |
25 | | struct IndexQueryContext { |
26 | | io::IOContext* io_ctx = nullptr; |
27 | | OlapReaderStatistics* stats = nullptr; |
28 | | RuntimeState* runtime_state = nullptr; |
29 | | |
30 | | CollectionStatisticsPtr collection_statistics; |
31 | | CollectionSimilarityPtr collection_similarity; |
32 | | |
33 | | size_t query_limit = 0; |
34 | | bool is_asc = false; |
35 | | |
36 | | // G02 count-only fast-path handshake. Set by SegmentIterator ONLY while it |
37 | | // evaluates the single pushed-down MATCH predicate of a COUNT_ON_INDEX scan |
38 | | // whose row space is provably unfiltered (no deletes, no other conjuncts, |
39 | | // full row bitmap, no row-id consumers -- see count_on_index_fastpath.h), |
40 | | // and reset immediately after. When set, an index reader MAY answer the |
41 | | // query with a bitmap whose CARDINALITY equals the match count without the |
42 | | // row ids being real (SNII returns [0, df) straight from dict-entry df, |
43 | | // skipping the posting decode). Readers must never cache such a bitmap |
44 | | // under a key a row-accurate query could hit. |
45 | | bool count_on_index_fastpath = false; |
46 | | |
47 | | // ---- Reply direction: fields a READER writes and the CALLER reads back ---- |
48 | | // |
49 | | // A caller that hands a reader a COPY of this context rather than the context itself must |
50 | | // fold the copy back with merge_reader_outputs(), or the reader's reply is dropped in |
51 | | // silence: nothing fails to compile, no test goes red, the query simply takes the wrong plan. |
52 | | // FunctionSearch's SNII leaf builder is such a caller -- it copies the context so the reader |
53 | | // publishes its BM25 into a throwaway CollectionSimilarity instead of the query's own. |
54 | | // |
55 | | // Every field added below this line must also be merged in merge_reader_outputs(). |
56 | | |
57 | | // G03 reply direction of the same handshake. Set by a reader iff it DID |
58 | | // answer with such a fabricated count bitmap (never on a query-cache hit, |
59 | | // a single-flight shared result, or any row-accurate decode). Read and |
60 | | // reset by SegmentIterator right after the index apply; a true value is |
61 | | // the precondition for the count-emission shortcut that materializes the |
62 | | // remaining count as default rows without iterating the row bitmap. |
63 | | bool count_on_index_fastpath_hit = false; |
64 | | |
65 | | // Folds the reply-direction fields a reader wrote on a copy of this context back into it. |
66 | | // Latching (never clearing) is what makes this safe to call for each of several readers. |
67 | 4 | void merge_reader_outputs(const IndexQueryContext& reader_context) { |
68 | 4 | count_on_index_fastpath_hit |= reader_context.count_on_index_fastpath_hit; |
69 | 4 | } |
70 | | }; |
71 | | using IndexQueryContextPtr = std::shared_ptr<IndexQueryContext>; |
72 | | |
73 | | } // namespace doris::segment_v2 |