YugabyteDB (2.13.1.0-b60, 21121d69985fbf76aa6958d8f04a9bfa936293b5)

Coverage Report

Created: 2022-03-22 16:43

/Users/deen/code/yugabyte-db/src/yb/common/pg_types.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_COMMON_PG_TYPES_H
15
#define YB_COMMON_PG_TYPES_H
16
17
#include <boost/functional/hash/hash.hpp>
18
19
#include "yb/common/entity_ids.h"
20
21
namespace yb {
22
23
// Postgres object identifier (OID).
24
typedef uint32_t PgOid;
25
static constexpr PgOid kPgInvalidOid = 0;
26
static constexpr PgOid kPgByteArrayOid = 17;
27
28
// A struct to identify a Postgres object by oid and the database oid it belongs to.
29
struct PgObjectId {
30
  PgOid database_oid = kPgInvalidOid;
31
  PgOid object_oid = kPgInvalidOid;
32
33
  PgObjectId(PgOid db_oid, PgOid obj_oid)
34
31.9M
      : database_oid(db_oid), object_oid(obj_oid) {}
35
36
  PgObjectId()
37
9.26M
      : database_oid(kPgInvalidOid), object_oid(kPgInvalidOid) {}
38
39
  explicit PgObjectId(const TableId& table_id);
40
41
160k
  bool IsValid() const {
42
160k
    return database_oid != kPgInvalidOid && 
object_oid != kPgInvalidOid115k
;
43
160k
  }
44
45
9.47M
  TableId GetYbTableId() const {
46
9.47M
    return GetPgsqlTableId(database_oid, object_oid);
47
9.47M
  }
48
49
143
  TablegroupId GetYbTablegroupId() const {
50
143
    return GetPgsqlTablegroupId(database_oid, object_oid);
51
143
  }
52
53
124
  TablespaceId GetYbTablespaceId() const {
54
124
    return GetPgsqlTablespaceId(object_oid);
55
124
  }
56
57
  std::string ToString() const;
58
59
16.7M
  bool operator== (const PgObjectId& other) const {
60
16.7M
    return database_oid == other.database_oid && 
object_oid == other.object_oid16.6M
;
61
16.7M
  }
62
63
33.3M
  friend std::size_t hash_value(const PgObjectId& id) {
64
33.3M
    std::size_t value = 0;
65
33.3M
    boost::hash_combine(value, id.database_oid);
66
33.3M
    boost::hash_combine(value, id.object_oid);
67
33.3M
    return value;
68
33.3M
  }
69
70
  template <class PB>
71
28.6k
  void ToPB(PB* pb) const {
72
28.6k
    pb->set_database_oid(database_oid);
73
28.6k
    pb->set_object_oid(object_oid);
74
28.6k
  }
75
76
  template <class PB>
77
59.1k
  static PgObjectId FromPB(const PB& pb) {
78
59.1k
    return PgObjectId(pb.database_oid(), pb.object_oid());
79
59.1k
  }
80
81
  template <class PB>
82
10.8k
  static TableId GetYbTableIdFromPB(const PB& pb) {
83
10.8k
    return FromPB(pb).GetYbTableId();
84
10.8k
  }
85
};
86
87
typedef boost::hash<PgObjectId> PgObjectIdHash;
88
89
0
inline std::ostream& operator<<(std::ostream& out, const PgObjectId& id) {
90
0
  return out << id.ToString();
91
0
}
92
93
}  // namespace yb
94
95
#endif  // YB_COMMON_PG_TYPES_H