CUBRID Engine  latest
btree_unique.cpp
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 #include "btree_unique.hpp"
24 
25 #include "string_buffer.hpp"
26 
27 #include <utility>
28 
30  : m_rows (keys + nulls)
31  , m_keys (keys)
32  , m_nulls (nulls)
33 {
34 }
35 
37  : btree_unique_stats (0, 0)
38 {
39 }
40 
43 {
44  return m_keys;
45 }
46 
49 {
50  return m_rows;
51 }
52 
55 {
56  return m_nulls;
57 }
58 
59 void
61 {
62  ++m_keys;
63  ++m_rows;
64 }
65 
66 void
68 {
69  ++m_nulls;
70  ++m_rows;
71 }
72 
73 void
75 {
76  ++m_rows;
77 }
78 
79 void
81 {
82  --m_keys;
83  --m_rows;
84 }
85 
86 void
88 {
89  --m_nulls;
90  --m_rows;
91 }
92 
93 void
95 {
96  --m_rows;
97 }
98 
99 bool
101 {
102  return m_keys == 0 && m_nulls == 0;
103 }
104 
105 bool
107 {
108  return m_rows == m_keys + m_nulls;
109 }
110 
113 {
114  m_rows = us.m_rows;
115  m_keys = us.m_keys;
116  m_nulls = us.m_nulls;
117 
118  return *this;
119 }
120 
121 void
123 {
124  m_rows += us.m_rows;
125  m_keys += us.m_keys;
126  m_nulls += us.m_nulls;
127 }
128 
129 void
131 {
132  m_rows -= us.m_rows;
133  m_keys -= us.m_keys;
134  m_nulls -= us.m_nulls;
135 }
136 
137 void
139 {
140  strbuf ("oids=%d keys=%d nulls=%d", m_rows, m_keys, m_nulls);
141 }
142 
143 void
145 {
146  new (this) multi_index_unique_stats ();
147 }
148 
149 void
151 {
152  this->~multi_index_unique_stats ();
153 }
154 
155 void
157 {
158  assert (!BTID_IS_NULL (&index));
159  m_stats_map[index] += us;
160 }
161 
162 void
164 {
165  assert (!BTID_IS_NULL (&index));
166  m_stats_map[index] = btree_unique_stats ();
167 }
168 
169 void
171 {
172  m_stats_map.clear ();
173 }
174 
177 {
178  return m_stats_map;
179 }
180 
181 bool
183 {
184  return m_stats_map.empty ();
185 }
186 
189 {
190  assert (!BTID_IS_NULL (&index));
191  return m_stats_map[index];
192 }
193 
194 void
196 {
197  strbuf ("{");
198  for (container_type::const_iterator it = m_stats_map.cbegin (); it != m_stats_map.cend (); ++it)
199  {
200  if (it != m_stats_map.cbegin ())
201  {
202  strbuf (", ");
203  }
204  strbuf ("{btid=%d|%d|%d, ", it->first.root_pageid, it->first.vfid.volid, it->first.vfid.fileid);
205  it->second.to_string (strbuf);
206  strbuf ("}");
207  }
208  strbuf ("}");
209 }
210 
213 {
214  m_stats_map = std::move (other.m_stats_map);
215  return *this;
216 }
217 
218 void
220 {
221  // collector all stats from other.m_stats_map
222  for (const auto &it : other.m_stats_map)
223  {
224  m_stats_map[it.first] += it.second;
225  }
226 }
void add_empty(const BTID &index)
void add_index_stats(const BTID &index, const btree_unique_stats &us)
void to_string(string_buffer &strbuf) const
bool is_unique() const
stat_type get_key_count() const
void operator-=(const btree_unique_stats &us)
#define assert(x)
std::int64_t stat_type
stat_type get_null_count() const
std::map< BTID, btree_unique_stats, btid_comparator > container_type
btree_unique_stats & operator=(const btree_unique_stats &us)
btree_unique_stats & get_stats_of(const BTID &index)
void operator+=(const btree_unique_stats &us)
stat_type get_row_count() const
multi_index_unique_stats & operator=(multi_index_unique_stats &&other)
container_type m_stats_map
bool is_zero() const
const container_type & get_map() const
void to_string(string_buffer &strbuf) const
#define BTID_IS_NULL(btid)
void operator+=(const multi_index_unique_stats &other)