MySQL 9.7.0
Source Code Documentation
Is_table_with_cursor Concept Reference

Concept that identifies that a class is a "table with cursor". More...

#include <table_with_cursor.h>

Concept definition

template<class Type>
std::is_default_constructible_v<Type> &&
requires(Type object, int index, PSI_field *field) {
{ object.advance() };
{ object.get_cursor() } -> Is_trivially_comparable;
{ object.set_cursor(object.get_cursor()) };
{ object.is_at_end() } -> std::convertible_to<bool>;
{ object.copy_field(index, field) };
{ Type::get_approximate_row_count() } -> std::convertible_to<int>;
{ Type::get_table_name() } -> std::same_as<const char *>;
{ Type::get_table_definition() } -> std::same_as<const char *>;
}
Concept that identifies that a class is a "table with cursor".
Definition: table_with_cursor.h:132
Concept requiring that objects are copyable using memcpy, and equality-testable using memcmp.
Definition: table_with_cursor.h:59
bool index(const std::string &value, const String &search_for, uint32_t *idx)
Definition: contains.h:76
MediaType
Definition: media_type.h:33
struct PSI_field PSI_field
This is an opaque structure to denote field in plugin/component code.
Definition: pfs_plugin_table_service.h:93

Detailed Description

Concept that identifies that a class is a "table with cursor".

A table with cursor can be used to define a performance_schema table, using get_table_share_from_table_with_cursor.

An object represent a view over a snapshot of a table, together with a row cursor. The cursor should at any time be positioned either on a row, or at one-past-the-last-element. The class should implement the following members:

  • Default constructor: Must ensure that the object holds a snapshot of the table, and must position the cursor at the first row. (Or if the table is empty, position the cursor at one-past-the-last-row.)
  • advance() const: Must advance the cursor to the next row, if it is not already at the end.
  • get_cursor() const: Must return a cursor object that represents the current position. The return type must model Is_trivially_comparable.
  • set_cursor(Position): Given an object returned from get_cursor(), or a bytewise copy of one, this function must move the cursor to that position. The parameter type must be the same as the return type for get_cursor().
  • is_at_end() const -> bool: Must return true if the cursor position is at one-past-the-last-element, and false otherwise.
  • copy_field(int from_index, PSI_field *to_field) const: Must copy the value of the current row, in the column with the given index, to to_field.
  • static get_approximate_row_count() -> int: This is optional. If given, it should return an approximation of the row count. The value is only used as a hint, so it may be good for performance if it is accurate, but there is no strict requirement that it is consistent with the actual table size.
  • static get_table_name() -> const char *: Must return the table name as a string.
  • static get_table_definition() -> const char *: Must return the table definition as a string.
Note
Tables can also be defined using the "handler interface" directly. The handler interface is C-oriented and has several legacy limitations, whereas "Table with cursor" is intended as a more C++-friendly alternative. It overcomes the limitations that implementations of the handler interface must...
  • Define global functions. Table with cursor just requires user to define member functions, which may be more natural as they operate on an object.
  • Expose a non-const pointer to the cursor, which the user may alter outside the control of the implementation. This violates OOP principles. Table with cursor does not have to do that.
  • Position cursors at one-before-the-beginning. This is different from most iterator idioms. Table with cursor only has to support cursors positioned on a row or at one-past-the-last-row.
  • Implement unusual requirements on the cursor type. This could not be worked around in table with cursor, but the requirement is modeled using a C++20 concept, providing partial type safety.
  • Initialize the table using lengthy boilerplate code. Table with cursor implements that once and for all in an internal function that does not have to be re-implemented per table.
  • By convention, use slightly cryptic names for some functions. Table with cursor attempts to use more straightforward names.

tparam Type the class to test