YugabyteDB (2.13.1.0-b60, 21121d69985fbf76aa6958d8f04a9bfa936293b5)

Coverage Report

Created: 2022-03-22 16:43

/Users/deen/code/yugabyte-db/src/yb/yql/pggate/pg_tabledesc.h
Line
Count
Source
1
//--------------------------------------------------------------------------------------------------
2
// Copyright (c) YugaByte, Inc.
3
//
4
// Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
5
// in compliance with the License.  You may obtain a copy of the License at
6
//
7
// http://www.apache.org/licenses/LICENSE-2.0
8
//
9
// Unless required by applicable law or agreed to in writing, software distributed under the License
10
// is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
11
// or implied.  See the License for the specific language governing permissions and limitations
12
// under the License.
13
//
14
//
15
// Structure definitions for a Postgres table descriptor.
16
//--------------------------------------------------------------------------------------------------
17
18
#ifndef YB_YQL_PGGATE_PG_TABLEDESC_H_
19
#define YB_YQL_PGGATE_PG_TABLEDESC_H_
20
21
#include "yb/common/partition.h"
22
#include "yb/common/pg_types.h"
23
#include "yb/common/pgsql_protocol.pb.h"
24
#include "yb/common/schema.h"
25
26
#include "yb/client/yb_op.h"
27
#include "yb/client/yb_table_name.h"
28
29
#include "yb/master/master_ddl.pb.h"
30
31
#include "yb/yql/pggate/pg_column.h"
32
#include "yb/yql/pggate/ybc_pg_typedefs.h"
33
34
namespace yb {
35
namespace pggate {
36
37
//--------------------------------------------------------------------------------------------------
38
39
// This class can be used to describe any reference of a column.
40
class PgTableDesc : public RefCountedThreadSafe<PgTableDesc> {
41
 public:
42
  PgTableDesc(const PgObjectId& id, const master::GetTableSchemaResponsePB& resp,
43
              std::shared_ptr<client::VersionedTablePartitionList> partitions);
44
45
  CHECKED_STATUS Init();
46
47
13.1M
  const PgObjectId& id() const {
48
13.1M
    return id_;
49
13.1M
  }
50
51
  const client::YBTableName& table_name() const;
52
53
  const PartitionSchema& partition_schema() const;
54
55
  size_t num_hash_key_columns() const;
56
  size_t num_key_columns() const;
57
  size_t num_columns() const;
58
59
  // Find the column given the postgres attr number.
60
  Result<size_t> FindColumn(int attr_num) const;
61
62
  Result<YBCPgColumnInfo> GetColumnInfo(int16_t attr_number) const;
63
64
  bool IsHashPartitioned() const;
65
66
  bool IsRangePartitioned() const;
67
68
  const std::vector<std::string>& GetPartitions() const;
69
70
  const std::string& LastPartition() const;
71
72
  size_t GetPartitionCount() const;
73
74
  // When reading a row given its associated ybctid, the ybctid value is decoded to the row.
75
  Result<string> DecodeYbctid(const Slice& ybctid) const;
76
77
  // Seek the tablet partition where the row whose "ybctid" value was given can be found.
78
  Result<size_t> FindPartitionIndex(const Slice& ybctid) const;
79
80
  // These values are set by  PgGate to optimize query to narrow the scanning range of a query.
81
  CHECKED_STATUS SetScanBoundary(PgsqlReadRequestPB *req,
82
                                 const string& partition_lower_bound,
83
                                 bool lower_bound_is_inclusive,
84
                                 const string& partition_upper_bound,
85
                                 bool upper_bound_is_inclusive);
86
87
  const Schema& schema() const;
88
89
  bool IsColocated() const;
90
91
  YBCPgOid GetColocationId() const;
92
93
  uint32_t schema_version() const;
94
95
 private:
96
  PgObjectId id_;
97
  master::GetTableSchemaResponsePB resp_;
98
  const std::shared_ptr<const client::VersionedTablePartitionList> table_partitions_;
99
100
  client::YBTableName table_name_;
101
  Schema schema_;
102
  PartitionSchema partition_schema_;
103
104
  // Attr number to column index map.
105
  std::unordered_map<int, size_t> attr_num_map_;
106
};
107
108
}  // namespace pggate
109
}  // namespace yb
110
111
#endif  // YB_YQL_PGGATE_PG_TABLEDESC_H_