MySQL  8.0.12
Source Code Documentation
read0types.h
Go to the documentation of this file.
1 /*
2  Copyright (c) 1997, 2018, Oracle and/or its affiliates. All Rights Reserved.
3 
4 
5 
6 
7 
8 
9 
10 
11 
12 
13 
14 
15 
16 
17 
18 
19 
20 
21 
22 
23 
24  The lines above are intentionally left blank
25 */
26 
27 /** @file include/read0types.h
28  Cursor read
29 
30  Created 2/16/1997 Heikki Tuuri
31  *******************************************************/
32 
33 #ifndef read0types_h
34 #define read0types_h
35 
36 #include <algorithm>
37 #include "dict0mem.h"
38 
39 #include "trx0types.h"
40 
41 // Friend declaration
42 class MVCC;
43 
44 /** Read view lists the trx ids of those transactions for which a consistent
45 read should not see the modifications to the database. */
46 
47 class ReadView {
48  /** This is similar to a std::vector but it is not a drop
49  in replacement. It is specific to ReadView. */
50  class ids_t {
51  typedef trx_ids_t::value_type value_type;
52 
53  /**
54  Constructor */
55  ids_t() : m_ptr(), m_size(), m_reserved() {}
56 
57  /**
58  Destructor */
60 
61  /**
62  Try and increase the size of the array. Old elements are
63  copied across. It is a no-op if n is < current size.
64 
65  @param n Make space for n elements */
66  void reserve(ulint n);
67 
68  /**
69  Resize the array, sets the current element count.
70  @param n new size of the array, in elements */
71  void resize(ulint n) {
72  ut_ad(n <= capacity());
73 
74  m_size = n;
75  }
76 
77  /**
78  Reset the size to 0 */
79  void clear() { resize(0); }
80 
81  /**
82  @return the capacity of the array in elements */
83  ulint capacity() const { return (m_reserved); }
84 
85  /**
86  Copy and overwrite the current array contents
87 
88  @param start Source array
89  @param end Pointer to end of array */
90  void assign(const value_type *start, const value_type *end);
91 
92  /**
93  Insert the value in the correct slot, preserving the order.
94  Doesn't check for duplicates. */
95  void insert(value_type value);
96 
97  /**
98  @return the value of the first element in the array */
99  value_type front() const {
100  ut_ad(!empty());
101 
102  return (m_ptr[0]);
103  }
104 
105  /**
106  @return the value of the last element in the array */
107  value_type back() const {
108  ut_ad(!empty());
109 
110  return (m_ptr[m_size - 1]);
111  }
112 
113  /**
114  Append a value to the array.
115  @param value the value to append */
116  void push_back(value_type value);
117 
118  /**
119  @return a pointer to the start of the array */
120  trx_id_t *data() { return (m_ptr); };
121 
122  /**
123  @return a const pointer to the start of the array */
124  const trx_id_t *data() const { return (m_ptr); };
125 
126  /**
127  @return the number of elements in the array */
128  ulint size() const { return (m_size); }
129 
130  /**
131  @return true if size() == 0 */
132  bool empty() const { return (size() == 0); }
133 
134  private:
135  // Prevent copying
136  ids_t(const ids_t &);
137  ids_t &operator=(const ids_t &);
138 
139  private:
140  /** Memory for the array */
141  value_type *m_ptr;
142 
143  /** Number of active elements in the array */
144  ulint m_size;
145 
146  /** Size of m_ptr in elements */
147  ulint m_reserved;
148 
149  friend class ReadView;
150  };
151 
152  public:
153  ReadView();
154  ~ReadView();
155  /** Check whether transaction id is valid.
156  @param[in] id transaction id to check
157  @param[in] name table name */
158  static void check_trx_id_sanity(trx_id_t id, const table_name_t &name);
159 
160  /** Check whether the changes by id are visible.
161  @param[in] id transaction id to check against the view
162  @param[in] name table name
163  @return whether the view sees the modifications of id. */
164  bool changes_visible(trx_id_t id, const table_name_t &name) const
165  MY_ATTRIBUTE((warn_unused_result)) {
166  ut_ad(id > 0);
167 
168  if (id < m_up_limit_id || id == m_creator_trx_id) {
169  return (true);
170  }
171 
173 
174  if (id >= m_low_limit_id) {
175  return (false);
176 
177  } else if (m_ids.empty()) {
178  return (true);
179  }
180 
181  const ids_t::value_type *p = m_ids.data();
182 
183  return (!std::binary_search(p, p + m_ids.size(), id));
184  }
185 
186  /**
187  @param id transaction to check
188  @return true if view sees transaction id */
189  bool sees(trx_id_t id) const { return (id < m_up_limit_id); }
190 
191  /**
192  Mark the view as closed */
193  void close() {
196  }
197 
198  /**
199  @return true if the view is closed */
200  bool is_closed() const { return (m_closed); }
201 
202  /**
203  Write the limits to the file.
204  @param file file to write to */
205  void print_limits(FILE *file) const {
206  fprintf(file,
207  "Trx read view will not see trx with"
208  " id >= " TRX_ID_FMT ", sees < " TRX_ID_FMT "\n",
210  }
211 
212  /**
213  @return the low limit no */
214  trx_id_t low_limit_no() const { return (m_low_limit_no); }
215 
216  /**
217  @return the low limit id */
218  trx_id_t low_limit_id() const { return (m_low_limit_id); }
219 
220  /**
221  @return true if there are no transaction ids in the snapshot */
222  bool empty() const { return (m_ids.empty()); }
223 
224 #ifdef UNIV_DEBUG
225  /**
226  @param rhs view to compare with
227  @return truen if this view is less than or equal rhs */
228  bool le(const ReadView *rhs) const {
229  return (m_low_limit_no <= rhs->m_low_limit_no);
230  }
231 
232  trx_id_t up_limit_id() const { return (m_up_limit_id); }
233 #endif /* UNIV_DEBUG */
234  private:
235  /**
236  Copy the transaction ids from the source vector */
237  inline void copy_trx_ids(const trx_ids_t &trx_ids);
238 
239  /**
240  Opens a read view where exactly the transactions serialized before this
241  point in time are seen in the view.
242  @param id Creator transaction id */
243  inline void prepare(trx_id_t id);
244 
245  /**
246  Complete the read view creation */
247  inline void complete();
248 
249  /**
250  Copy state from another view. Must call copy_complete() to finish.
251  @param other view to copy from */
252  inline void copy_prepare(const ReadView &other);
253 
254  /**
255  Complete the copy, insert the creator transaction id into the
256  m_trx_ids too and adjust the m_up_limit_id *, if required */
257  inline void copy_complete();
258 
259  /**
260  Set the creator transaction id, existing id must be 0 */
262  ut_ad(m_creator_trx_id == 0);
264  }
265 
266  friend class MVCC;
267 
268  private:
269  // Disable copying
270  ReadView(const ReadView &);
271  ReadView &operator=(const ReadView &);
272 
273  private:
274  /** The read should not see any transaction with trx id >= this
275  value. In other words, this is the "high water mark". */
277 
278  /** The read should see all trx ids which are strictly
279  smaller (<) than this value. In other words, this is the
280  low water mark". */
282 
283  /** trx id of creating transaction, set to TRX_ID_MAX for free
284  views. */
286 
287  /** Set of RW transactions that was active when this snapshot
288  was taken */
290 
291  /** The view does not need to see the undo logs for transactions
292  whose transaction number is strictly smaller (<) than this value:
293  they can be removed in purge if not needed by other views */
295 
296  /** AC-NL-RO transaction view that has been "closed". */
297  bool m_closed;
298 
299  typedef UT_LIST_NODE_T(ReadView) node_t;
300 
301  /** List of read views in trx_sys */
302  byte pad1[64 - sizeof(node_t)];
303  node_t m_view_list;
304 };
305 
306 #endif
unsigned char byte
Blob class.
Definition: common.h:159
The MVCC read view manager.
Definition: read0read.h:43
byte pad1[64 - sizeof(node_t)]
List of read views in trx_sys.
Definition: read0types.h:302
Data dictionary memory object creation.
trx_id_t m_creator_trx_id
trx id of creating transaction, set to TRX_ID_MAX for free views.
Definition: read0types.h:285
void insert(value_type value)
Insert the value in the correct slot, preserving the order.
Definition: read0read.cc:282
trx_id_t m_up_limit_id
The read should see all trx ids which are strictly smaller (<) than this value.
Definition: read0types.h:281
void creator_trx_id(trx_id_t id)
Set the creator transaction id, existing id must be 0.
Definition: read0types.h:261
bool empty() const
Definition: read0types.h:132
trx_id_t low_limit_id() const
Definition: read0types.h:218
value_type * m_ptr
Memory for the array.
Definition: read0types.h:141
void resize(ulint n)
Resize the array, sets the current element count.
Definition: read0types.h:71
const string name("\ame\)
trx_ids_t::value_type value_type
Definition: read0types.h:51
typedef UT_LIST_NODE_T(ReadView) node_t
void copy_complete()
Complete the copy, insert the creator transaction id into the m_trx_ids too and adjust the m_up_limit...
Definition: read0read.cc:638
#define UT_DELETE_ARRAY(ptr)
Destroy, deallocate and trace the deallocation of an array created by UT_NEW_ARRAY() or UT_NEW_ARRAY_...
Definition: ut0new.h:982
ulint m_reserved
Size of m_ptr in elements.
Definition: read0types.h:147
Read view lists the trx ids of those transactions for which a consistent read should not see the modi...
Definition: read0types.h:47
bool changes_visible(trx_id_t id, const table_name_t &name) const
Check whether the changes by id are visible.
Definition: read0types.h:164
void reserve(ulint n)
Try and increase the size of the array.
Definition: read0read.cc:217
ulint capacity() const
Definition: read0types.h:83
void copy_trx_ids(const trx_ids_t &trx_ids)
Copy the transaction ids from the source vector.
Definition: read0read.cc:356
#define TRX_ID_FMT
printf(3) format used for printing DB_TRX_ID and other system fields
Definition: trx0types.h:50
bool m_closed
AC-NL-RO transaction view that has been "closed".
Definition: read0types.h:297
void prepare(trx_id_t id)
Opens a read view where exactly the transactions serialized before this point in time are seen in the...
Definition: read0read.cc:424
ulint size() const
Definition: read0types.h:128
This is similar to a std::vector but it is not a drop in replacement.
Definition: read0types.h:50
static void check_trx_id_sanity(trx_id_t id, const table_name_t &name)
Check whether transaction id is valid.
Definition: trx0sys.cc:62
trx_id_t m_low_limit_no
The view does not need to see the undo logs for transactions whose transaction number is strictly sma...
Definition: read0types.h:294
trx_id_t up_limit_id() const
Definition: read0types.h:232
ids_t & operator=(const ids_t &)
value_type front() const
Definition: read0types.h:99
value_type back() const
Definition: read0types.h:107
bool le(const ReadView *rhs) const
Definition: read0types.h:228
Table name wrapper for pretty-printing.
Definition: dict0mem.h:444
Cursor end()
A past-the-end Cursor.
Definition: rules_table_service.cc:191
trx_id_t m_low_limit_id
The read should not see any transaction with trx id >= this value.
Definition: read0types.h:276
bool sees(trx_id_t id) const
Definition: read0types.h:189
ids_t()
Constructor.
Definition: read0types.h:55
bool empty() const
Definition: read0types.h:222
void copy_prepare(const ReadView &other)
Copy state from another view.
Definition: read0read.cc:614
void push_back(value_type value)
Append a value to the array.
Definition: read0read.cc:269
void assign(const value_type *start, const value_type *end)
Copy and overwrite the current array contents.
Definition: read0read.cc:247
friend class ReadView
Definition: read0types.h:149
ids_t m_ids
Set of RW transactions that was active when this snapshot was taken.
Definition: read0types.h:289
void print_limits(FILE *file) const
Write the limits to the file.
Definition: read0types.h:205
#define TRX_ID_MAX
Maximum transaction identifier.
Definition: trx0types.h:155
void clear()
Reset the size to 0.
Definition: read0types.h:79
Transaction system global type definitions.
void complete()
Complete the read view creation.
Definition: read0read.cc:451
trx_id_t low_limit_no() const
Definition: read0types.h:214
trx_id_t * data()
Definition: read0types.h:120
fprintf(outf, " %%time sec #call ms/call %%calls weight stack name\)
~ReadView()
ReadView destructor.
Definition: read0read.cc:325
~ids_t()
Destructor.
Definition: read0types.h:59
#define ut_ad(EXPR)
Debug assertion.
Definition: ut0dbg.h:60
ulint m_size
Number of active elements in the array.
Definition: read0types.h:144
ib_id_t trx_id_t
Transaction identifier (DB_TRX_ID, DATA_TRX_ID)
Definition: trx0types.h:148
node_t m_view_list
Definition: read0types.h:303
const trx_id_t * data() const
Definition: read0types.h:124
bool is_closed() const
Definition: read0types.h:200
std::vector< trx_id_t, ut_allocator< trx_id_t > > trx_ids_t
Definition: trx0types.h:426
const char * p
Definition: ctype-mb.cc:1221
const string value("\alue\)
#define id
Definition: lexyy.cc:961
void close()
Mark the view as closed.
Definition: read0types.h:193