YugabyteDB (2.13.1.0-b60, 21121d69985fbf76aa6958d8f04a9bfa936293b5)

Coverage Report

Created: 2022-03-22 16:43

/Users/deen/code/yugabyte-db/src/yb/docdb/doc_ql_scanspec.h
Line
Count
Source (jump to first uncovered line)
1
// Copyright (c) YugaByte, Inc.
2
//
3
// Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
4
// in compliance with the License.  You may obtain a copy of the License at
5
//
6
// http://www.apache.org/licenses/LICENSE-2.0
7
//
8
// Unless required by applicable law or agreed to in writing, software distributed under the License
9
// is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
10
// or implied.  See the License for the specific language governing permissions and limitations
11
// under the License.
12
//
13
14
#ifndef YB_DOCDB_DOC_QL_SCANSPEC_H
15
#define YB_DOCDB_DOC_QL_SCANSPEC_H
16
17
#include <functional>
18
19
#include "yb/rocksdb/options.h"
20
21
#include "yb/common/ql_scanspec.h"
22
23
#include "yb/docdb/docdb_fwd.h"
24
#include "yb/docdb/key_bytes.h"
25
26
namespace yb {
27
namespace docdb {
28
29
// DocDB variant of QL scanspec.
30
class DocQLScanSpec : public QLScanSpec {
31
 public:
32
33
  // Scan for the specified doc_key. If the doc_key specify a full primary key, the scan spec will
34
  // not include any static column for the primary key. If the static columns are needed, a separate
35
  // scan spec can be used to read just those static columns.
36
  DocQLScanSpec(const Schema& schema, const DocKey& doc_key,
37
      const rocksdb::QueryId query_id, const bool is_forward_scan = true);
38
39
  // Scan for the given hash key and a condition. If a start_doc_key is specified, the scan spec
40
  // will not include any static column for the start key. If the static columns are needed, a
41
  // separate scan spec can be used to read just those static columns.
42
  //
43
  // Note: std::reference_wrapper is used instead of raw lvalue reference to prevent
44
  // temporary objects usage. The following code wont compile:
45
  //
46
  // DocQLScanSpec spec(...{} /* hashed_components */,...);
47
48
  DocQLScanSpec(const Schema& schema, boost::optional<int32_t> hash_code,
49
                boost::optional<int32_t> max_hash_code,
50
                std::reference_wrapper<const std::vector<PrimitiveValue>> hashed_components,
51
                const QLConditionPB* req, const QLConditionPB* if_req,
52
                rocksdb::QueryId query_id, bool is_forward_scan = true,
53
                bool include_static_columns = false,
54
                const DocKey& start_doc_key = DefaultStartDocKey());
55
56
  // Return the inclusive lower and upper bounds of the scan.
57
  Result<KeyBytes> LowerBound() const;
58
  Result<KeyBytes> UpperBound() const;
59
60
  // Create file filter based on range components.
61
  std::shared_ptr<rocksdb::ReadFileFilter> CreateFileFilter() const;
62
63
  // Gets the query id.
64
7.29M
  const rocksdb::QueryId QueryId() const {
65
7.29M
    return query_id_;
66
7.29M
  }
67
68
7.39M
  const std::shared_ptr<std::vector<std::vector<PrimitiveValue>>>& range_options() const {
69
7.39M
    return range_options_;
70
7.39M
  }
71
72
0
  bool include_static_columns() const {
73
0
    return include_static_columns_;
74
0
  }
75
76
7.38M
  const QLScanRange* range_bounds() const {
77
7.38M
    return range_bounds_.get();
78
7.38M
  }
79
80
25.7M
  const Schema* schema() const override { return &schema_; }
81
82
62.1k
  const std::vector<ColumnId> range_options_indexes() const {
83
62.1k
    return range_options_indexes_;
84
62.1k
  }
85
86
62.1k
  const std::vector<ColumnId> range_bounds_indexes() const {
87
62.1k
    return range_bounds_indexes_;
88
62.1k
  }
89
90
 private:
91
  static const DocKey& DefaultStartDocKey();
92
93
  // Return inclusive lower/upper range doc key considering the start_doc_key.
94
  Result<KeyBytes> Bound(const bool lower_bound) const;
95
96
  // Initialize range_options_ if hashed_components_ in set and all range columns have one or more
97
  // options (i.e. using EQ/IN conditions). Otherwise range_options_ will stay null and we will
98
  // only use the range_bounds for scanning.
99
  void InitRangeOptions(const QLConditionPB& condition);
100
101
  // Returns the lower/upper doc key based on the range components.
102
  KeyBytes bound_key(const bool lower_bound) const;
103
104
  // Returns the lower/upper range components of the key.
105
  std::vector<PrimitiveValue> range_components(const bool lower_bound) const;
106
107
  // The scan range within the hash key when a WHERE condition is specified.
108
  const std::unique_ptr<const QLScanRange> range_bounds_;
109
110
  // Indexes of columns that have range bounds such as c2 < 4 AND c2 >= 1
111
  std::vector<ColumnId> range_bounds_indexes_;
112
113
  // Schema of the columns to scan.
114
  const Schema& schema_;
115
116
  // Hash code to scan at (interpreted as lower bound if hashed_components_ are empty)
117
  // hash values are positive int16_t
118
  const boost::optional<int32_t> hash_code_;
119
120
  // Max hash code to scan at (upper bound, only useful if hashed_components_ are empty)
121
  // hash values are positive int16_t
122
  const boost::optional<int32_t> max_hash_code_;
123
124
  // The hashed_components are owned by the caller of QLScanSpec.
125
  const std::vector<PrimitiveValue>* hashed_components_;
126
127
  // The range value options if set. (possibly more than one due to IN conditions).
128
  std::shared_ptr<std::vector<std::vector<PrimitiveValue>>> range_options_;
129
130
  // Indexes of columns that have range option filters such as
131
  // c2 IN (1, 5, 6, 9)
132
  std::vector<ColumnId> range_options_indexes_;
133
134
  // Does the scan include static columns also?
135
  const bool include_static_columns_;
136
137
  // Specific doc key to scan if not empty.
138
  const KeyBytes doc_key_;
139
140
  // Starting doc key when requested by the client.
141
  const KeyBytes start_doc_key_;
142
143
  // Lower/upper doc keys basing on the range.
144
  const KeyBytes lower_doc_key_;
145
  const KeyBytes upper_doc_key_;
146
147
  // Query ID of this scan.
148
  const rocksdb::QueryId query_id_;
149
150
  DISALLOW_COPY_AND_ASSIGN(DocQLScanSpec);
151
};
152
153
}  // namespace docdb
154
}  // namespace yb
155
156
#endif // YB_DOCDB_DOC_QL_SCANSPEC_H