MySQL 9.7.0
Source Code Documentation
jdv Namespace Reference

Classes

class  Content_tree_node
 
struct  Json_type_traits
 
struct  Json_type_traits< Json_array >
 
struct  Json_type_traits< Json_object >
 
class  Key_column_info
 Class to represent each key and column information from JSON duality object. More...
 
struct  Resolve_column
 Represents columns in the base table which will be populated based on the Json document passed in. More...
 
struct  Resolve_row
 Holds the resolved values for a row of a base table. More...
 
struct  Single_object_binding
 Binds a single Json_object and a jdv::Content_tree_node. More...
 
struct  Size_first_comparator
 Comparator which orders in the same way as Json_object orders its keys. More...
 
struct  Two_object_binding
 Binds two Json_objects (existing_object and new_object) and a jdv::Content_tree_node. More...
 
class  View_lex_handler
 Class to handle view Lex. More...
 

Typedefs

using Resolve_column_vec = std::vector< Resolve_column >
 
template<typename T >
using Index_entry = std::reference_wrapper< T >
 Convenience alias. More...
 
template<typename T >
using Index = std::span< Index_entry< T > >
 Convenience alias. More...
 

Enumerations

enum  Duality_view_tags : int {
  DVT_INVALID = 0 , DVT_INSERT = 1 , DVT_UPDATE = 2 , DVT_DELETE = 4 ,
  DVT_NOINSERT = 8 , DVT_NOUPDATE = 16 , DVT_NODELETE = 32
}
 
enum class  Stmt_state { EXECUTE = 0 , SKIP = 1 , ERROR = 2 }
 

Functions

static const char * get_primary_key_column_name (const Table_ref *table_ref)
 Returns primary key name given table. More...
 
static Fieldget_field_for_column (const Table_ref *table_ref, const char *fld_name)
 Get the field instance of a column. More...
 
static bool set_join_column_index_for_node (Content_tree_node *child_node, Content_tree_node *parent_node, Item_ident *side_ident, bool is_parent)
 Helper function to set join column index for a given node. More...
 
static bool prepare_join_condition (THD *thd, Query_block *sl, Content_tree_node *node)
 Helper function to prepare join condition for sub-object. More...
 
static bool prepare_content_tree_node (THD *thd, Content_tree_node *node)
 
Content_tree_nodeprepare_content_tree (THD *thd, LEX *view_lex)
 Constructs the content tree for given JSON duality view. More...
 
void destroy_content_tree (Content_tree_node *root)
 Deletes the content tree for given JSON duality view. More...
 
static bool validate_view_syntax (THD *thd, Query_expression *qe, const char *object_name, bool root_query)
 Performs syntax validation of a given JSON DUALITY VIEW. More...
 
static bool meets_relationship_rules (Content_tree_node *node)
 Performs validation of below semantic rules: More...
 
static bool is_column_with_unsupported_type_projected (Content_tree_node *node)
 Performs validation of below semantic rules: More...
 
static bool meets_all_semantic_rules (Content_tree_node *node, std::map< std::string, Mem_root_array< Key_column_info > * > &table_columns_map)
 Apply duality view create rules. More...
 
static bool validate_view_semantics (Content_tree_node *root, std::map< std::string, Mem_root_array< Key_column_info > * > &table_columns_map)
 Performs semantic validation of a given JSON DUALITY VIEW. More...
 
bool is_prepare_required (THD *thd, Table_ref *table_ref)
 Check if duality view prepared is required. More...
 
bool prepare (THD *thd, Table_ref *table_ref)
 Performs Syntax validation, parepares metadata tree and performs Semantic validation of a given JSON DUALITY VIEW. More...
 
static const char * em_wrap (const char *arg)
 
static int em_wrap (int arg)
 
static std::string em_wrap (std::string_view sv)
 Overload which wraps string_views in strings which are guaranteed to be null-terminated. More...
 
static std::string em_wrap (const Json_path &jp)
 Overload which wraps Json_paths in strings, after first creating string representation in String buffer. More...
 
static decltype(auto) em_unwrap (auto arg)
 Identity unwrapper. More...
 
static const char * em_unwrap (const std::string &str)
 Overload which unwraps strings by calling c_str()-. More...
 
template<int CODE, typename... Args>
static void my_jdv_error (Args... args_to_wrap)
 Wraps calls to my_error() unwrapping wrapped arguments. More...
 
template<typename JT >
static JT * inspect_valid_dom (Json_dom *valid_dom)
 Inspects an assumed valid Json_dom (typically an exising value in UPDATE). More...
 
template<typename JT >
static std::pair< enum_json_type, JT * > inspect_dom (Json_dom *dom)
 Inspects a Json_dom which may or may not have the expected type and may also be nullptr, (typically a value provided as user input). More...
 
static std::string json_wrapper_to_string (const Json_wrapper &jw)
 Formats a Json_wrapper as string for debugging. More...
 
static std::string json_dom_to_string (Json_dom *jdom)
 Formats a Json_dom as string for debugging. More...
 
static bool is_nil_dom (Json_dom *jdom)
 Predicate to determine if a dom does not represent a valid value i.e. More...
 
static bool is_auto_increment (const Field &fld)
 Convenience wrapper predicate which returns true for AUTO_INCREMENT columns. More...
 
static int compare_doms (Json_dom *ajd, Json_dom *bjd)
 Compares Json_dom pointers which may be nullptr by considering nullptrs to be greater than all non-nullptr values. More...
 
static bool expect_b64_dom (enum_field_types ft, const CHARSET_INFO &csi)
 Predicate to determine if json dom is expected to be base64 encoded based on SQL type and charset-. More...
 
static bool col_expects_b64 (const Key_column_info &kci)
 Predicate to determine if base column expects json values to be base64 encoded. More...
 
static bool append_b64_dom (std::string *sbufp, const String &buf, Json_dom *jd)
 Converts base64 string to its binary representation, escapes this to be a string literal, wraps in single quotes, prepends character set introducer _binary before appending to statement. More...
 
static bool append_json_dom (std::string *sbufp, Json_dom *jd, bool b64=false)
 Append a Json_dom to a string. More...
 
static bool do_in_substatement_context (THD *thd, auto &&f)
 Sets up the environment for using Regular_statement_handle for JDVs. More...
 
static Json_domget_val (const Json_object *jo, std::string_view k)
 Convenience function for obtaining the member of a Json_object. More...
 
static bool is_zero (Json_dom *doc)
 Convenience function for comparing a Json document to unsigned 0. More...
 
static bool auto_generate_on_zero (THD *thd)
 Convenience function for checking if the connection supports using 0 to request explicit generation of AUTO_INCREMENT values. More...
 
static bool field_will_be_auto_generated (THD *thd, const Field &fld, Json_dom *doc)
 Convenience function which checks if a Json document value inserted in a field will result in a generated AUTO_INCREMENT value. More...
 
static std::ostream & operator<< (std::ostream &os, const Resolve_column &rc)
 
static std::ostream & operator<< (std::ostream &os, const Resolve_row &rr)
 
template<typename BIN >
static int compare_bindings (const BIN &abin, const BIN &bbin)
 Compares bindings based on: More...
 
static std::ostream & operator<< (std::ostream &os, const Single_object_binding &bin)
 
static Json_domget_pk_dom (const Two_object_binding &bin)
 Returns either the existing or the resolved pk value for a Two_object_binding. More...
 
static std::ostream & operator<< (std::ostream &os, const Two_object_binding &bin)
 
template<typename T >
static int operator<=> (const Index_entry< T > &a, const Index_entry< T > &b)
 Spaceship operator which forwards to the indexed type. More...
 
template<typename T >
static bool operator== (const Index_entry< T > &a, const Index_entry< T > &b)
 Equality operator which forwards to the indexed type. More...
 
static const TABLE_SHAREget_share (const auto &bin)
 Convenience function which returns the TABLE_SHARE* for the binding. More...
 
static std::string_view get_table_cache_key (const auto &bin)
 Convenience function which returns the table_cache_key of the binding as a std::string_view. More...
 
template<typename RT , typename BIN >
static Index< RT > make_mr_index (THD *thd, BIN &bindings)
 Create an index over the bindings vector which is allocated on THD::mem_root. More...
 
static bool resolve_column_range (const std::ranges::random_access_range auto &bindings)
 Goes through the input json (bound_object) and uses the join condition to infer column values which are not provided explicitly. More...
 
static bool resolve_columns (const std::ranges::random_access_range auto &bindings)
 Iterates over a range of bindings and initializes the resolve_columns vector. More...
 
static Json_domget_pk_dom (const Single_object_binding &bin)
 Returns the resolved pk value for a Single_object binding. More...
 
static const Resolve_columnget_pk_rc (const auto &bin)
 Returns a const ref to the Resolve_row of the primary key column. More...
 
static int get_deferred_resolve_weight (const auto &bin)
 Returns an integer weight which allows sorting bindings with deferred_resolve for the primary key after non-generated values. More...
 
template<typename BV >
static bool check_for_share_pk_duplicates (THD *thd, BV &bindings)
 Creates an index over the bindings sorted on TABLE_SHARE* and pk-dom value. More...
 
static void merge_bindings_for_update (Index< Two_object_binding > &bindings)
 Merges bindings for existing and input rows when doing UPDATE. More...
 
static bool check_for_unmatched_input_keys (THD *thd, Json_object *input_obj, const Content_tree_node &ct_node)
 Check Json_object being passed in for keys which are not present in the JDV definition (including _metadata for the root object), and report error if that is the case. More...
 
static bool is_equal (Json_dom *ajd, Json_dom *bjd)
 Compare Json_doms for equality using a Json_wrapper. More...
 
static std::unique_ptr< Resolve_rowmake_rr_up (Resolve_row *parent)
 Helper function to create unique_ptr to Resolve_row. More...
 
static bool push_object_child_bindings (std::size_t pbx, const Content_tree_node *child_ct_node, std::vector< Single_object_binding > *stack)
 Overload for Single_object_binding (INSERT/DELETE) with Json_object (JSON_OBJECT). More...
 
static bool push_array_child_bindings (std::size_t pbx, const Content_tree_node *child_ct_node, std::vector< Single_object_binding > *stack)
 Overload for Single_object_binding (INSERT/DELETE) with Json_array (JSON_ARRAYAGG). More...
 
static bool push_object_child_bindings (std::size_t pbx, const Content_tree_node *child_ct_node, std::vector< Two_object_binding > *stack)
 Overload for Two_object_binding (UPDATE) with Json_object (JSON_OBJECT). More...
 
static bool push_array_child_bindings (std::size_t pbx, const Content_tree_node *child_ct_node, std::vector< Two_object_binding > *stack)
 Overload for Two_object_binding (UPDATE) with Json_array (JSON_ARRAY_AGG). More...
 
template<typename BIN >
static bool flatten (std::vector< BIN > *stack)
 Takes a stack (std::vector) with a single binding at the top. More...
 
static std::optional< std::vector< bool > > select_diff_vector (THD *thd, const auto &binding)
 Check if the row represented by the binding already exists, and if so return a diff vector (true for columns which currently does not have the value of the binding). More...
 
static bool run_substmt (THD *thd, Diagnostics_area *caller_da, std::string_view stmt, ulonglong *affected_rows)
 Uses a Regular_statement_handle to execute a single statement passed as argument. More...
 
static Stmt_state make_insert (THD *thd, const auto &binding, auto *sbufp)
 Produces an INSERT statement from a binding. More...
 
static Stmt_state make_delete (THD *, const Single_object_binding &binding, auto *sbufp)
 Produces a delete statement from a Single_object_binding. More...
 
static Json_dometag_dom (Json_object *root_object)
 Obtains the dom of the etag sub-object. More...
 
static bool check_etag (const Two_object_binding &binding)
 Checks if etags in existing and bound objects match. More...
 
static Stmt_state make_update (THD *thd, const Two_object_binding &binding, auto *sbufp)
 Produces an UPDATE statement from a Two_object_binding. More...
 
static bool check_input_json (Json_dom *input_dom)
 
static bool jdv_handle_insert (THD *thd, Json_wrapper *jw, Content_tree_node *ct_node, ulonglong *affected_rows)
 Creates bindings from inserted Json_object, orders them, creates and executes INSERT statements against the base tables. More...
 
static bool jdv_handle_update (THD *thd, Json_wrapper *jw, Json_wrapper *existing, Content_tree_node *ct_node, ulonglong *affected_rows)
 Creates bindings from existing and updated Json_object, orders them, creates and executes UPDATE/INSERT/DELETE statements against the base tables. More...
 
static bool jdv_handle_delete (THD *thd, Json_wrapper *jw, Content_tree_node *ct_node, ulonglong *affected_rows)
 Creates bindings from deleted Json_object, orders them, creates and executes DELETE statements against the base tables. More...
 
static bool jdv_prepare_base (THD *thd, const Table_ref *view, bool is_single_table_plan)
 Performs common sanity checks. More...
 
bool jdv_prepare_insert (THD *thd, const Table_ref *view, Sql_cmd_insert_base *sql_insert_cmd)
 Performs sanity checks specific to insert. More...
 
bool jdv_prepare_update (THD *thd, const Table_ref *view, bool is_single_table_plan)
 Performs sanity checks specific to update. More...
 
bool jdv_prepare_delete (THD *thd, const Table_ref *view, bool is_single_table_plan)
 Performs sanity checks specific to delete. More...
 
static decltype(auto) create_sctx_guard (THD *thd, const Table_ref *dvtr)
 Installs the view's security context if it exists and creates a scope guard to restore the original context. More...
 
static bool write_binlog (THD *thd)
 Performs statement-based binlogging for DML operations on a JSON Duality view. More...
 
bool jdv_insert (THD *thd, const Table_ref *dvtr, const mem_root_deque< List_item * > &values)
 Entry point called from sql_insert.cc, bool Sql_cmd_insert_values::execute_inner(THD *thd);. More...
 
bool jdv_update (THD *thd, const Table_ref *dvtr, const mem_root_deque< Item * > *seldq, const mem_root_deque< Item * > *upddq, ulonglong *affected_rows)
 Entry point called from sql_update.cc bool Sql_cmd_update::update_single_table(THD *thd);. More...
 
bool jdv_delete (THD *thd, const Table_ref *dvtr, ulonglong *affected_rows)
 Entry point called from sql_delete.cc, bool Sql_cmd_delete::delete_from_single_table(THD *thd);. More...
 
void get_i_s_properties (Content_tree_node *root, const char *i_s_view_name, String *properties)
 Get the requested properies for the JSON duality view represented by the submitted content tree root. More...
 
const char * str (const Content_tree_node::Type &ctnt)
 
std::ostream & operator<< (std::ostream &os, const Content_tree_node &ctn)
 
std::ostream & operator<< (std::ostream &os, const Key_column_info &kci)
 
std::string path_str (const Json_dom *doc)
 
decltype(auto) func_or (auto *p, auto f, auto val)
 
void append_identifier (std::string *sbuf, std::string_view id, String *bufp)
 Append an identifier to a string using backtick quotes. More...
 
void append_identifier (std::string *sbuf, std::string_view id)
 Append an identifier to a string using backtick quotes using a String on the stack as buffer. More...
 

Variables

static thread_local uint next_id = 0
 
constexpr std::size_t VOID_COLUMN_INDEX
 
static constexpr std::string_view metadatakey = "_metadata"
 
static constexpr std::string_view etagkey = "etag"
 
constexpr Size_first_comparator size_less
 
static constexpr std::string_view TYPE_HEADER_PREFIX = "base64:type"
 
static constexpr std::size_t TYPE_HEADER_MAXSZ
 
static constexpr auto ERROR_INDICATOR = static_cast<std::size_t>(-1)
 
static Json_uint ZERO {0}
 Reusable object to simplify comparisons against uint 0 (explicit generation request) More...
 
static const Json_wrapper ZEROW {&ZERO, true}
 Reusable Json_wrapper around ZERO object to simplify comparisons against uint 0 (explicit generation request) More...
 
template<typename T >
static auto unwrap_index_entry
 Lambda object to unwrap an index entry. More...
 
static auto share_pk_less
 Less comparator which compares Index_entry objects based on their TABLE_SHARE and primary key column value. More...
 
constexpr std::size_t STMT_RESERVE_SIZE = 512
 
constexpr std::size_t BINDINGS_RESERVE_SIZE = 48
 

Typedef Documentation

◆ Index

template<typename T >
using jdv::Index = typedef std::span<Index_entry<T> >

Convenience alias.

◆ Index_entry

template<typename T >
using jdv::Index_entry = typedef std::reference_wrapper<T>

Convenience alias.

◆ Resolve_column_vec

using jdv::Resolve_column_vec = typedef std::vector<Resolve_column>

Enumeration Type Documentation

◆ Duality_view_tags

Enumerator
DVT_INVALID 
DVT_INSERT 
DVT_UPDATE 
DVT_DELETE 
DVT_NOINSERT 
DVT_NOUPDATE 
DVT_NODELETE 

◆ Stmt_state

enum class jdv::Stmt_state
strong
Enumerator
EXECUTE 
SKIP 
ERROR 

Function Documentation

◆ append_b64_dom()

static bool jdv::append_b64_dom ( std::string *  sbufp,
const String buf,
Json_dom jd 
)
static

Converts base64 string to its binary representation, escapes this to be a string literal, wraps in single quotes, prepends character set introducer _binary before appending to statement.

Checks to see if input is valid base64.

Parameters
sbufpstatement buffer
bufstring representation of dom
jddom (for error reporting)
Returns
true in case of errors

◆ append_identifier() [1/2]

void jdv::append_identifier ( std::string *  sbuf,
std::string_view  id 
)

Append an identifier to a string using backtick quotes using a String on the stack as buffer.

◆ append_identifier() [2/2]

void jdv::append_identifier ( std::string *  sbuf,
std::string_view  id,
String bufp 
)

Append an identifier to a string using backtick quotes.

Pointer to String to use as buffer passed in.

◆ append_json_dom()

static bool jdv::append_json_dom ( std::string *  sbufp,
Json_dom jd,
bool  b64 = false 
)
static

Append a Json_dom to a string.

If the Json_dom pointer is nullptr 'DEFAULT' is appended. If the json type is J_NULL, 'NULL' is appended. For numeric values the bare to_string value is appended. For other non-base64 types the to_string value is quote escaped and wrapped in single quotes with the character set introducer _utf8mb4.

If the base table column returns values as base64 the raw string representation of the dom is expected to be a type header followed by a base64 encoded payload. This is handled by append_b64_dom().

Parameters
sbufpstatement buffer
jddom to convert to string and append
b64true if resulting string is expected to be base64 encoded
Returns
true if error

◆ auto_generate_on_zero()

static bool jdv::auto_generate_on_zero ( THD thd)
static

Convenience function for checking if the connection supports using 0 to request explicit generation of AUTO_INCREMENT values.

Parameters
thdTHD
Returns
true if supported

◆ check_etag()

static bool jdv::check_etag ( const Two_object_binding binding)
static

Checks if etags in existing and bound objects match.

Succeeds with warning if etag is not provided in bound object.

Parameters
bindingroot binding
Returns
true if error (mismatch)

◆ check_for_share_pk_duplicates()

template<typename BV >
static bool jdv::check_for_share_pk_duplicates ( THD thd,
BV &  bindings 
)
static

Creates an index over the bindings sorted on TABLE_SHARE* and pk-dom value.

Verifies that duplicates are identical for all columns and marks it as empty. Otherwise reports error.

Parameters
thdTHD
bindingsbindings vector
Returns
true if error

◆ check_for_unmatched_input_keys()

static bool jdv::check_for_unmatched_input_keys ( THD thd,
Json_object input_obj,
const Content_tree_node ct_node 
)
static

Check Json_object being passed in for keys which are not present in the JDV definition (including _metadata for the root object), and report error if that is the case.

Parameters
thdThread handle.
input_objinput object
ct_nodejdv definition
Returns
true if error

◆ check_input_json()

static bool jdv::check_input_json ( Json_dom input_dom)
static

◆ col_expects_b64()

static bool jdv::col_expects_b64 ( const Key_column_info kci)
static

Predicate to determine if base column expects json values to be base64 encoded.

Parameters
kcibase table column
Returns
true if column expects json values to be base64 encooded

◆ compare_bindings()

template<typename BIN >
static int jdv::compare_bindings ( const BIN &  abin,
const BIN &  bbin 
)
static

Compares bindings based on:

  • fk_dep_weight,
  • jdv::Content_tree_node pointer value,
  • resolved primary key value Sorting with this comparator < 0 orders bindings so that inserts don't violate fk-constraints, and groups statements for the same SO ordered by pk so that duplicates can be found and removed.
  • In addition to this it is necessary to maintain a predictable order also for bindings with the same primary key value, so that half-bindings (bindings which have either only the existing or only the bound object) can be correctly merged, and duplicates in user input identified.
Parameters
abinlhs
bbinrhs
Returns
-1,0,1 for less, equal, greater.

◆ compare_doms()

static int jdv::compare_doms ( Json_dom ajd,
Json_dom bjd 
)
static

Compares Json_dom pointers which may be nullptr by considering nullptrs to be greater than all non-nullptr values.

This convention is chosen so that sorting with {compare_doms(a,b) < 0} places nullptr entries last (the assumption being that searches into the sorted range most often are for a non-nullptr elements).

Parameters
ajdlhs
bjdrhs
Returns
-1,0,1 for less, equal, greater.

◆ create_sctx_guard()

static decltype(auto) jdv::create_sctx_guard ( THD thd,
const Table_ref dvtr 
)
static

Installs the view's security context if it exists and creates a scope guard to restore the original context.

Parameters
thdTHD
dvtrduality view reference
Returns
scope guard which restores original security context

◆ destroy_content_tree()

void jdv::destroy_content_tree ( Content_tree_node root)

Deletes the content tree for given JSON duality view.

Parameters
[in]rootRoot object of content tree

◆ do_in_substatement_context()

static bool jdv::do_in_substatement_context ( THD thd,
auto &&  f 
)
static

Sets up the environment for using Regular_statement_handle for JDVs.

The creation and usage of the Regular_statement_handle is done in the callable F passed in which returns true to indicate errors. The caller DA is passed as an argument to F. The callable f is responsible for copying information back to caller_da if/when needed.

Parameters
thdTHD
fcallable to invoke
Returns
value of f

◆ em_unwrap() [1/2]

static decltype(auto) jdv::em_unwrap ( auto  arg)
static

Identity unwrapper.

Parameters
argargument to return
Returns
argument passed in

◆ em_unwrap() [2/2]

static const char * jdv::em_unwrap ( const std::string &  str)
static

Overload which unwraps strings by calling c_str()-.

Parameters
strstring to call c_str() on
Returns
c-string from string

◆ em_wrap() [1/4]

static const char * jdv::em_wrap ( const char *  arg)
static

◆ em_wrap() [2/4]

static std::string jdv::em_wrap ( const Json_path jp)
static

Overload which wraps Json_paths in strings, after first creating string representation in String buffer.

This allows passing Json_paths directly to error message function as const char *without having to worry about ownership.

Parameters
jpJson_path to wrap
Returns
std:string containing the string representation of the path

◆ em_wrap() [3/4]

static int jdv::em_wrap ( int  arg)
static

◆ em_wrap() [4/4]

static std::string jdv::em_wrap ( std::string_view  sv)
static

Overload which wraps string_views in strings which are guaranteed to be null-terminated.

Parameters
svstring view to wrap.
Returns
string containing copy of argument

◆ etag_dom()

static Json_dom * jdv::etag_dom ( Json_object root_object)
static

Obtains the dom of the etag sub-object.

Parameters
root_objectcontaining the etag sub-object
Returns
etag sub-object dom

◆ expect_b64_dom()

static bool jdv::expect_b64_dom ( enum_field_types  ft,
const CHARSET_INFO csi 
)
static

Predicate to determine if json dom is expected to be base64 encoded based on SQL type and charset-.

Parameters
ftactual field type
csicharacter set object
Returns
true if json dom is expected to be base64 encooded

◆ field_will_be_auto_generated()

static bool jdv::field_will_be_auto_generated ( THD thd,
const Field fld,
Json_dom doc 
)
static

Convenience function which checks if a Json document value inserted in a field will result in a generated AUTO_INCREMENT value.

Parameters
thdTHD
fldField object describing column
docJson_dom value to insert
Returns
true if a generated value will be inserted

◆ flatten()

template<typename BIN >
static bool jdv::flatten ( std::vector< BIN > *  stack)
static

Takes a stack (std::vector) with a single binding at the top.

Creates bindings for all the children of that binding by combining each Json child with the corresponding CTN child and place these on the stack. Proceeds with the next element now on the stack. When there are no more element left on the stack the process is complete and the stack contains a flattened sequence of bindings for each Json_object in the input which corresponds to a jdv::Content_tree_node. This flattened sequence can then be sorted and traversed in either direction as needed when generating statements for the base tables.

Parameters
stackbinding stack
Returns
true if error

◆ func_or()

decltype(auto) jdv::func_or ( auto *  p,
auto  f,
auto  val 
)

◆ get_deferred_resolve_weight()

static int jdv::get_deferred_resolve_weight ( const auto &  bin)
static

Returns an integer weight which allows sorting bindings with deferred_resolve for the primary key after non-generated values.

Parameters
binBinding
Returns
1 if primary key has deferred resolve, 0 otherwise

◆ get_field_for_column()

static Field * jdv::get_field_for_column ( const Table_ref table_ref,
const char *  fld_name 
)
static

Get the field instance of a column.

Parameters
[in]table_refTable_ref instance of a table.
[in]fld_nameField name.
Returns
Field instance if found, nullptr otherwise.

◆ get_i_s_properties()

void jdv::get_i_s_properties ( Content_tree_node root,
const char *  i_s_view_name,
String properties 
)

Get the requested properies for the JSON duality view represented by the submitted content tree root.

The i_s_view_name will imply which properties are requested. The properties are filled into a JSON document which is serialized into a string returned to the UDF invoked from the view, and is used there to join with the JSON duality view name retrieved from the DD tables.

Parameters
rootContent tree root.
i_s_view_nameName of the I_S view.
propertiesString containing the requested properties.

◆ get_pk_dom() [1/2]

static Json_dom * jdv::get_pk_dom ( const Single_object_binding bin)
static

Returns the resolved pk value for a Single_object binding.

Parameters
binbinding to get pk dom for
Returns
dom representing PK

◆ get_pk_dom() [2/2]

static Json_dom * jdv::get_pk_dom ( const Two_object_binding bin)
static

Returns either the existing or the resolved pk value for a Two_object_binding.

Parameters
binbinding to get pk dom for
Returns
dom representing PK

◆ get_pk_rc()

static const Resolve_column & jdv::get_pk_rc ( const auto &  bin)
static

Returns a const ref to the Resolve_row of the primary key column.

Parameters
binBinding
Returns
Resolve_row for primary key column.

◆ get_primary_key_column_name()

static const char * jdv::get_primary_key_column_name ( const Table_ref table_ref)
static

Returns primary key name given table.

Parameters
[in]table_refTable_ref instance of a table. current THD
Returns
primary key column name if exists, otherwise nullptr.

◆ get_share()

static const TABLE_SHARE * jdv::get_share ( const auto &  bin)
static

Convenience function which returns the TABLE_SHARE* for the binding.

Parameters
binbinding
Returns
TABLE_SHARE* for the binding

◆ get_table_cache_key()

static std::string_view jdv::get_table_cache_key ( const auto &  bin)
static

Convenience function which returns the table_cache_key of the binding as a std::string_view.

Parameters
binbinding
Returns
std::string_view over the table_cache_key for the binding

◆ get_val()

static Json_dom * jdv::get_val ( const Json_object jo,
std::string_view  k 
)
static

Convenience function for obtaining the member of a Json_object.

Returns nullptr if the Json_object argument is nullptr or does not have the requested key.

◆ inspect_dom()

template<typename JT >
static std::pair< enum_json_type, JT * > jdv::inspect_dom ( Json_dom dom)
static

Inspects a Json_dom which may or may not have the expected type and may also be nullptr, (typically a value provided as user input).

Returns {J_NULL,nullptr} if the argument is nullptr or has type J_NULL. Returns {J_ERROR, nullptr} if the argument does not have type JT. Otherwise returns {enum_json_type of JT, argument cast to JT*}.

Template Parameters
JTthe expected actual type of the argument
Parameters
domdom that may not have the expected type
Returns
pair of actual json type enum value and the argument cast to JT* or nullptr

◆ inspect_valid_dom()

template<typename JT >
static JT * jdv::inspect_valid_dom ( Json_dom valid_dom)
static

Inspects an assumed valid Json_dom (typically an exising value in UPDATE).

Returns nullptr if the argument is nullptr or has type J_NULL. Otherwise returns the dom cast JT*. Asserts if the type is not JT.

Template Parameters
JTthe expected actual type of the argument
Parameters
valid_domassumed valid Json_dom
Returns
the dom cast to the expectd type or nullptr

◆ is_auto_increment()

static bool jdv::is_auto_increment ( const Field fld)
static

Convenience wrapper predicate which returns true for AUTO_INCREMENT columns.

Parameters
fldcolumn to report for.
Returns
true if column is AUTO_INCREMENT

◆ is_column_with_unsupported_type_projected()

static bool jdv::is_column_with_unsupported_type_projected ( Content_tree_node node)
static

Performs validation of below semantic rules:

  1. Projection of JSON, GEOMETRY columns/fields is not supported
  2. Projection of Virtual columns/fields is not supported
Parameters
[in]nodecurrent node of metadata tree
Return values
truein case if unsupported column is projected

◆ is_equal()

static bool jdv::is_equal ( Json_dom ajd,
Json_dom bjd 
)
static

Compare Json_doms for equality using a Json_wrapper.

Parameters
ajdleft-hand side of comparison
bjdright-hand side of comparison
Returns
true if equal

◆ is_nil_dom()

static bool jdv::is_nil_dom ( Json_dom jdom)
static

Predicate to determine if a dom does not represent a valid value i.e.

that either the pointer itself is nullptr, or that the dom is a Json_null (has type enum_json_type::J_NULL).

Parameters
jdomdom to check
Returns
true if represents a void value

◆ is_prepare_required()

bool jdv::is_prepare_required ( THD thd,
Table_ref table_ref 
)

Check if duality view prepared is required.

Parameters
thdThread handle.
table_refTable_ref* object for given JSON duality view.
Returns
true If JDV prepare should be performed.
false Otherwise.

◆ is_zero()

static bool jdv::is_zero ( Json_dom doc)
static

Convenience function for comparing a Json document to unsigned 0.

Parameters
docJson document to test
Returns
true if doc compares equal to unsigned 0

◆ jdv_delete()

bool jdv::jdv_delete ( THD thd,
const Table_ref dvtr,
ulonglong affected_rows 
)

Entry point called from sql_delete.cc, bool Sql_cmd_delete::delete_from_single_table(THD *thd);.

Parameters
thdTHD
dvtrduality view
[out]affected_rowsNumber of affected rows.
Returns
true if error

◆ jdv_handle_delete()

static bool jdv::jdv_handle_delete ( THD thd,
Json_wrapper jw,
Content_tree_node ct_node,
ulonglong affected_rows 
)
static

Creates bindings from deleted Json_object, orders them, creates and executes DELETE statements against the base tables.

Parameters
thdTHD
jwexisting JSON object to delete
ct_nodecontent tree root node
[out]affected_rowsaffected base table rows

◆ jdv_handle_insert()

static bool jdv::jdv_handle_insert ( THD thd,
Json_wrapper jw,
Content_tree_node ct_node,
ulonglong affected_rows 
)
static

Creates bindings from inserted Json_object, orders them, creates and executes INSERT statements against the base tables.

Parameters
thdTHD
jwJSON object to insert
ct_nodecontent tree root node of view
[out]affected_rowsnumber of affected base table rows

◆ jdv_handle_update()

static bool jdv::jdv_handle_update ( THD thd,
Json_wrapper jw,
Json_wrapper existing,
Content_tree_node ct_node,
ulonglong affected_rows 
)
static

Creates bindings from existing and updated Json_object, orders them, creates and executes UPDATE/INSERT/DELETE statements against the base tables.

Parameters
thdTHD
jwupdated JSON object
existingexisting JSON object
ct_nodecontent tree root node
[out]affected_rowsaffected base table rows

◆ jdv_insert()

bool jdv::jdv_insert ( THD thd,
const Table_ref dvtr,
const mem_root_deque< List_item * > &  values 
)

Entry point called from sql_insert.cc, bool Sql_cmd_insert_values::execute_inner(THD *thd);.

Parameters
thdThread handle.
dvtrTable_ref instance of a duality view.
valuesValues.
Returns
true if error

◆ jdv_prepare_base()

static bool jdv::jdv_prepare_base ( THD thd,
const Table_ref view,
bool  is_single_table_plan 
)
static

Performs common sanity checks.

Parameters
thdTHD
viewJDV to check
is_single_table_plantrue if single table plan
Returns
true if error

◆ jdv_prepare_delete()

bool jdv::jdv_prepare_delete ( THD thd,
const Table_ref view,
bool  is_single_table_plan 
)

Performs sanity checks specific to delete.

Parameters
thdTHD
viewJDV to check
is_single_table_plantrue if single table plan
Returns
true if error

◆ jdv_prepare_insert()

bool jdv::jdv_prepare_insert ( THD thd,
const Table_ref view,
Sql_cmd_insert_base sql_insert_cmd 
)

Performs sanity checks specific to insert.

Parameters
thdTHD
viewJDV to check
sql_insert_cmdinsert command object
Returns
true if error

◆ jdv_prepare_update()

bool jdv::jdv_prepare_update ( THD thd,
const Table_ref view,
bool  is_single_table_plan 
)

Performs sanity checks specific to update.

Parameters
thdTHD
viewJDV to check
is_single_table_plantrue if single table plan
Returns
true if error

◆ jdv_update()

bool jdv::jdv_update ( THD thd,
const Table_ref dvtr,
const mem_root_deque< Item * > *  seldq,
const mem_root_deque< Item * > *  upddq,
ulonglong affected_rows 
)

Entry point called from sql_update.cc bool Sql_cmd_update::update_single_table(THD *thd);.

Parameters
thdTHD
dvtrduality view
seldqselected items
upddqupdated items
[out]affected_rowsNumber of affected rows.
Returns
true if error

◆ json_dom_to_string()

static std::string jdv::json_dom_to_string ( Json_dom jdom)
static

Formats a Json_dom as string for debugging.

Parameters
jdomJson_dom to format
Returns
string containing formatted representation

◆ json_wrapper_to_string()

static std::string jdv::json_wrapper_to_string ( const Json_wrapper jw)
static

Formats a Json_wrapper as string for debugging.

Parameters
jwJson_wrapper to format
Returns
string containing formatted representation

◆ make_delete()

static Stmt_state jdv::make_delete ( THD ,
const Single_object_binding binding,
auto *  sbufp 
)
static

Produces a delete statement from a Single_object_binding.

When an update decays into a DELETE, this function is called a with a Single_object_binding created on the fly from the Two_object_binding - which is only possible because DELETE does not require a populated resolve_row.

Parameters
bindingdeletee
sbufpstatement text buffer
Returns
Statement_status - indicates if statement must be executed, skipped or an error occured

◆ make_insert()

static Stmt_state jdv::make_insert ( THD thd,
const auto &  binding,
auto *  sbufp 
)
static

Produces an INSERT statement from a binding.

For INSERT this is a Single_object_binding, but when an update decays into an INSERT, this function is also invoked with a Two_object_binding.

Parameters
thdTHD
bindinginsertee
sbufpstatement text buffer
Returns
Statement_status - indicates if statement must be executed, skipped or an error occured

◆ make_mr_index()

template<typename RT , typename BIN >
static Index< RT > jdv::make_mr_index ( THD thd,
BIN &  bindings 
)
static

Create an index over the bindings vector which is allocated on THD::mem_root.

The index is a span over the memory buffer allocated on the mem_root.

Parameters
thdTHD
bindingsvector of bindings
Returns
Index

◆ make_rr_up()

static std::unique_ptr< Resolve_row > jdv::make_rr_up ( Resolve_row parent)
static

Helper function to create unique_ptr to Resolve_row.

(On mac std::make_unique() does not do init-list initialization).

Parameters
parentparent
Returns
resolve_row

◆ make_update()

static Stmt_state jdv::make_update ( THD thd,
const Two_object_binding binding,
auto *  sbufp 
)
static

Produces an UPDATE statement from a Two_object_binding.

If there is no existing object an INSERT is generated. If there is no bound object a DELETE statement is generated.

Parameters
thdTHD
bindingupdatee
sbufpstatement text buffer
Returns
Statement_status - indicates if statement must be executed, skipped or an error occured

◆ meets_all_semantic_rules()

static bool jdv::meets_all_semantic_rules ( Content_tree_node node,
std::map< std::string, Mem_root_array< Key_column_info > * > &  table_columns_map 
)
static

Apply duality view create rules.

Parameters
[in]nodecurrent object of metadata tree
[in,out]table_columns_mapmap of table name to column projections
Return values
truein case of success, false in case of failure

◆ meets_relationship_rules()

static bool jdv::meets_relationship_rules ( Content_tree_node node)
static

Performs validation of below semantic rules:

Rule: If child object is a singleton descendent, then primary key column of a child object's table should part of a join condition. If child is a nested descendent, then primary key column of a parent object should be part of a join condition.

Parameters
[in]nodeCurrent content tree node.
Return values
truein case of success, false in case of failure.

◆ merge_bindings_for_update()

static void jdv::merge_bindings_for_update ( Index< Two_object_binding > &  bindings)
static

Merges bindings for existing and input rows when doing UPDATE.

This cannot be done when binding as the pk value for the input row may not be known until after resolving.

Parameters
bindingsBinding index to merge

◆ my_jdv_error()

template<int CODE, typename... Args>
static void jdv::my_jdv_error ( Args...  args_to_wrap)
static

Wraps calls to my_error() unwrapping wrapped arguments.

Template Parameters
CODEerror code to report
Parameters
args_to_wraparguments for format specifiers in error message

◆ operator<<() [1/6]

std::ostream & jdv::operator<< ( std::ostream &  os,
const Content_tree_node ctn 
)

◆ operator<<() [2/6]

std::ostream & jdv::operator<< ( std::ostream &  os,
const Key_column_info kci 
)

◆ operator<<() [3/6]

static std::ostream & jdv::operator<< ( std::ostream &  os,
const Resolve_column rc 
)
static

◆ operator<<() [4/6]

static std::ostream & jdv::operator<< ( std::ostream &  os,
const Resolve_row rr 
)
static

◆ operator<<() [5/6]

static std::ostream & jdv::operator<< ( std::ostream &  os,
const Single_object_binding bin 
)
static

◆ operator<<() [6/6]

static std::ostream & jdv::operator<< ( std::ostream &  os,
const Two_object_binding bin 
)
static

◆ operator<=>()

template<typename T >
static int jdv::operator<=> ( const Index_entry< T > &  a,
const Index_entry< T > &  b 
)
static

Spaceship operator which forwards to the indexed type.

◆ operator==()

template<typename T >
static bool jdv::operator== ( const Index_entry< T > &  a,
const Index_entry< T > &  b 
)
static

Equality operator which forwards to the indexed type.

◆ path_str()

std::string jdv::path_str ( const Json_dom doc)

◆ prepare()

bool jdv::prepare ( THD thd,
Table_ref table_ref 
)

Performs Syntax validation, parepares metadata tree and performs Semantic validation of a given JSON DUALITY VIEW.

Parameters
[in]thdCurrent THD object
[in,out]table_refTable_ref* object for given JSON DUALITY VIEW
Return values
falsein case of success, true in case of failure

◆ prepare_content_tree()

Content_tree_node * jdv::prepare_content_tree ( THD thd,
LEX view_lex 
)

Constructs the content tree for given JSON duality view.

Parameters
[in]thdTHD context.
[in]view_lexLEX* object for the current query
Returns
Content_tree on success, nullptr otherwise.

◆ prepare_content_tree_node()

static bool jdv::prepare_content_tree_node ( THD thd,
Content_tree_node node 
)
static

◆ prepare_join_condition()

static bool jdv::prepare_join_condition ( THD thd,
Query_block sl,
Content_tree_node node 
)
static

Helper function to prepare join condition for sub-object.

Parameters
thdThread Handle.
slSub-object's query block.
nodeContent tree node for a sub-object.
Returns
true On failure.
false On success.

◆ push_array_child_bindings() [1/2]

static bool jdv::push_array_child_bindings ( std::size_t  pbx,
const Content_tree_node child_ct_node,
std::vector< Single_object_binding > *  stack 
)
static

Overload for Single_object_binding (INSERT/DELETE) with Json_array (JSON_ARRAYAGG).

The Json_array* argument is used as tag for choosing the correct overload, (instead of creating a separate tag type).

Parameters
pbxparent binding index
child_ct_nodechild content tree node
stackbinding stack
Returns
true if error

◆ push_array_child_bindings() [2/2]

static bool jdv::push_array_child_bindings ( std::size_t  pbx,
const Content_tree_node child_ct_node,
std::vector< Two_object_binding > *  stack 
)
static

Overload for Two_object_binding (UPDATE) with Json_array (JSON_ARRAY_AGG).

The Json_array* argument is used as tag for choosing the correct overload, (instead of creating a separate tag type).

Parameters
pbxparent binding index
child_ct_nodechild content tree node
stackbinding stack
Returns
true if error

◆ push_object_child_bindings() [1/2]

static bool jdv::push_object_child_bindings ( std::size_t  pbx,
const Content_tree_node child_ct_node,
std::vector< Single_object_binding > *  stack 
)
static

Overload for Single_object_binding (INSERT/DELETE) with Json_object (JSON_OBJECT).

The Json_object* argument is used as tag for choosing the correct overload, (instead of creating a separate tag type).

Parameters
pbxparent binding index
child_ct_nodechild content tree node
stackbinding stack
Returns
true if error

◆ push_object_child_bindings() [2/2]

static bool jdv::push_object_child_bindings ( std::size_t  pbx,
const Content_tree_node child_ct_node,
std::vector< Two_object_binding > *  stack 
)
static

Overload for Two_object_binding (UPDATE) with Json_object (JSON_OBJECT).

The Json_object* argument is used as tag for choosing the correct overload, (instead of creating a separate tag type).

Parameters
pbxparent binding index
child_ct_nodechild content tree node
stackbinding stack
Returns
true if error

◆ resolve_column_range()

static bool jdv::resolve_column_range ( const std::ranges::random_access_range auto &  bindings)
static

Goes through the input json (bound_object) and uses the join condition to infer column values which are not provided explicitly.

Reports error if the values provided in the input do not match what is expressed by the join condition.

Parameters
bindingsrange of bindings
Returns
true if error

◆ resolve_columns()

static bool jdv::resolve_columns ( const std::ranges::random_access_range auto &  bindings)
static

Iterates over a range of bindings and initializes the resolve_columns vector.

Then calls resolve_range to do the actual resolving.

Parameters
bindingsvector of bindings
Returns
true if error

◆ run_substmt()

static bool jdv::run_substmt ( THD thd,
Diagnostics_area caller_da,
std::string_view  stmt,
ulonglong affected_rows 
)
static

Uses a Regular_statement_handle to execute a single statement passed as argument.

Parameters
thdTHD
caller_daDA in which to accumulate diagnostics
stmtstatement text
[out]affected_rowsNumber of affected rows.
Returns
true if error

◆ select_diff_vector()

static std::optional< std::vector< bool > > jdv::select_diff_vector ( THD thd,
const auto &  binding 
)
static

Check if the row represented by the binding already exists, and if so return a diff vector (true for columns which currently does not have the value of the binding).

This function can only be called when already inside do_in_substatement_context().

Parameters
thdTHD
bindingcheckee
Returns
diff vector or nullopt if error or row not found

◆ set_join_column_index_for_node()

static bool jdv::set_join_column_index_for_node ( Content_tree_node child_node,
Content_tree_node parent_node,
Item_ident side_ident,
bool  is_parent 
)
static

Helper function to set join column index for a given node.

Parameters
child_nodeContent_tree_node object representing the current node
parent_nodeContent_tree_node object representing the parent node
side_identItem_ident object representing one side of equality condition
is_parentspecifies whether current node is to be processed or parent
Returns
true On failure.
false On success.

◆ str()

const char * jdv::str ( const Content_tree_node::Type ctnt)

◆ validate_view_semantics()

static bool jdv::validate_view_semantics ( Content_tree_node root,
std::map< std::string, Mem_root_array< Key_column_info > * > &  table_columns_map 
)
static

Performs semantic validation of a given JSON DUALITY VIEW.

Parameters
[in]rootObject of metadata tree
[in,out]table_columns_mapmap of table name to column projections
Return values
falsein case of success, true in case of failure

◆ validate_view_syntax()

static bool jdv::validate_view_syntax ( THD thd,
Query_expression qe,
const char *  object_name,
bool  root_query 
)
static

Performs syntax validation of a given JSON DUALITY VIEW.

Parameters
[in]thdCurrent THD object
[in]qeRoot object of metadata tree
[in]object_namekey name for sub-objects, "Root Node" for root node
[in]root_querydoes given qe represent root query expression?
Return values
falsein case of success, true in case of failure

◆ write_binlog()

static bool jdv::write_binlog ( THD thd)
static

Performs statement-based binlogging for DML operations on a JSON Duality view.

Parameters
thdTHD
Returns
true if error

Variable Documentation

◆ BINDINGS_RESERVE_SIZE

constexpr std::size_t jdv::BINDINGS_RESERVE_SIZE = 48
constexpr

◆ ERROR_INDICATOR

constexpr auto jdv::ERROR_INDICATOR = static_cast<std::size_t>(-1)
staticconstexpr

◆ etagkey

constexpr std::string_view jdv::etagkey = "etag"
staticconstexpr

◆ metadatakey

constexpr std::string_view jdv::metadatakey = "_metadata"
staticconstexpr

◆ next_id

thread_local uint jdv::next_id = 0
static

◆ share_pk_less

auto jdv::share_pk_less
static
Initial value:
= [](const auto &iea, const auto &ieb) {
const auto &abin = iea.get();
const auto &bbin = ieb.get();
if (get_share(abin) != get_share(bbin)) {
}
assert(abin.ct_node->primary_key_column_index() ==
bbin.ct_node->primary_key_column_index());
return compare_doms(get_pk_rc(abin).value, get_pk_rc(bbin).value) < 0;
}
static int compare_doms(Json_dom *ajd, Json_dom *bjd)
Compares Json_dom pointers which may be nullptr by considering nullptrs to be greater than all non-nu...
Definition: dml.cc:276
static const TABLE_SHARE * get_share(const auto &bin)
Convenience function which returns the TABLE_SHARE* for the binding.
Definition: dml.cc:813
static std::string_view get_table_cache_key(const auto &bin)
Convenience function which returns the table_cache_key of the binding as a std::string_view.
Definition: dml.cc:824
static const Resolve_column & get_pk_rc(const auto &bin)
Returns a const ref to the Resolve_row of the primary key column.
Definition: dml.cc:1096
ValueType value(const std::optional< ValueType > &v)
Definition: gtid.h:83

Less comparator which compares Index_entry objects based on their TABLE_SHARE and primary key column value.

◆ size_less

constexpr Size_first_comparator jdv::size_less
constexpr

◆ STMT_RESERVE_SIZE

constexpr std::size_t jdv::STMT_RESERVE_SIZE = 512
constexpr

◆ TYPE_HEADER_MAXSZ

constexpr std::size_t jdv::TYPE_HEADER_MAXSZ
staticconstexpr
Initial value:
=
TYPE_HEADER_PREFIX.size() + 4
static constexpr std::string_view TYPE_HEADER_PREFIX
Definition: dml.cc:340

◆ TYPE_HEADER_PREFIX

constexpr std::string_view jdv::TYPE_HEADER_PREFIX = "base64:type"
staticconstexpr

◆ unwrap_index_entry

template<typename T >
auto jdv::unwrap_index_entry
static
Initial value:
=
[](const Index_entry<T> &ie) -> T & { return ie.get(); }
#define T
Definition: jit_executor_value.cc:373
std::reference_wrapper< T > Index_entry
Convenience alias.
Definition: dml.cc:783

Lambda object to unwrap an index entry.

Useful to create transform_views or use as projection in algorithms.

◆ VOID_COLUMN_INDEX

constexpr std::size_t jdv::VOID_COLUMN_INDEX
constexpr
Initial value:
=
ValueType max(X &&first)
Definition: gtid.h:103

◆ ZERO

Json_uint jdv::ZERO {0}
static

Reusable object to simplify comparisons against uint 0 (explicit generation request)

◆ ZEROW

const Json_wrapper jdv::ZEROW {&ZERO, true}
static

Reusable Json_wrapper around ZERO object to simplify comparisons against uint 0 (explicit generation request)