CUBRID Engine  latest
btree_unique.hpp
Go to the documentation of this file.
1 /*
2  * Copyright 2008 Search Solution Corporation
3  * Copyright 2016 CUBRID Corporation
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * 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, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  *
17  */
18 
19 //
20 // Unique b-tree definitions
21 //
22 
23 #ifndef _BTREE_UNIQUE_HPP_
24 #define _BTREE_UNIQUE_HPP_
25 
26 #include "storage_common.h"
27 
28 #include <cstdint>
29 #include <map>
30 
31 // forward definitions
32 class string_buffer;
33 
35 {
36  public:
37  using stat_type = std::int64_t;
38 
40  btree_unique_stats (stat_type keys, stat_type nulls = 0);
41 
42  stat_type get_key_count () const;
43  stat_type get_row_count () const;
44  stat_type get_null_count () const;
45 
46  void insert_key_and_row ();
47  void insert_null_and_row ();
48  void add_row ();
49  void delete_key_and_row ();
50  void delete_null_and_row ();
51  void delete_row ();
52 
53  bool is_zero () const;
54  bool is_unique () const; // rows == keys + nulls
55 
57  void operator+= (const btree_unique_stats &us);
58  void operator-= (const btree_unique_stats &us);
59 
60  void to_string (string_buffer &strbuf) const;
61 
62  private:
63  // m_rows = m_keys + m_nulls
67 };
68 
70 {
71  private:
73  {
74  bool operator() (const BTID &a, const BTID &b) const
75  {
76  return a.root_pageid < b.root_pageid || (a.root_pageid == b.root_pageid && a.vfid.volid < b.vfid.volid);
77  }
78  };
79 
80  public:
81  multi_index_unique_stats () = default;
82  ~multi_index_unique_stats () = default;
83 
84  using container_type = std::map<BTID, btree_unique_stats, btid_comparator>;
85 
86  void construct ();
87  void destruct ();
88 
89  void add_index_stats (const BTID &index, const btree_unique_stats &us);
90  void add_empty (const BTID &index);
91  void clear ();
92 
93  const container_type &get_map () const;
94  bool empty () const;
95 
96  btree_unique_stats &get_stats_of (const BTID &index);
97 
98  void to_string (string_buffer &strbuf) const;
99 
102  void operator+= (const multi_index_unique_stats &other);
103 
104  private:
106 };
107 
108 #endif // !_BTREE_UNIQUE_HPP_
void to_string(string_buffer &strbuf) const
bool is_unique() const
INT32 root_pageid
stat_type get_key_count() const
void operator-=(const btree_unique_stats &us)
std::int64_t stat_type
stat_type get_null_count() const
VFID vfid
std::map< BTID, btree_unique_stats, btid_comparator > container_type
btree_unique_stats & operator=(const btree_unique_stats &us)
void operator+=(const btree_unique_stats &us)
stat_type get_row_count() const
container_type m_stats_map
bool is_zero() const
short volid
Definition: dbtype_def.h:887
void clear(cub_regex_object *&regex, char *&pattern)