MySQL 8.0.40
Source Code Documentation
|
#include <table_function.h>
Public Member Functions | |
Table_function_json (const char *alias, Item *a, List< Json_table_column > *cols) | |
~Table_function_json () override | |
const char * | func_name () const override |
Returns function's name. More... | |
bool | init () override |
Initialize the table function before creation of result table. More... | |
bool | fill_result_table () override |
Execute table function. More... | |
table_map | used_tables () override |
Return table_map of tables used by function's data source. More... | |
bool | print (const THD *thd, String *str, enum_query_type query_type) const override |
JSON_TABLE printout. More... | |
bool | walk (Item_processor processor, enum_walk walk, uchar *arg) override |
Public Member Functions inherited from Table_function | |
Table_function () | |
virtual | ~Table_function ()=default |
bool | create_result_table (THD *thd, ulonglong options, const char *table_alias) |
Create, but not instantiate the result table. More... | |
bool | write_row () |
Write current record to the result table and handle overflow to disk. More... | |
Field * | get_field (uint i) |
Returns a field with given index. More... | |
void | empty_table () |
Delete all rows in the table. More... | |
void | default_row () |
Set the default row. More... | |
virtual bool | init_args () |
Initialize table function after the result table has been created. More... | |
void | cleanup () |
Clean up table function after one execution. More... | |
void | destroy () |
Destroy table function object after all executions are complete. More... | |
Private Member Functions | |
bool | fill_json_table () |
Fill the result table. More... | |
bool | init_json_table_col_lists (uint *nest_idx, Json_table_column *parent) |
Initialize columns and lists for json table. More... | |
void | set_subtree_to_null (Json_table_column *root, Json_table_column **last) |
A helper function which sets all columns under given NESTED PATH column to nullptr. More... | |
List< Create_field > * | get_field_list () override |
Return list of fields to create result table from. More... | |
bool | do_init_args () override |
Check whether given default values can be saved to fields. More... | |
void | do_cleanup () override |
Private Attributes | |
std::array< JT_data_source, MAX_NESTED_PATH > | m_jds |
Array of JSON Data Source for each NESTED PATH clause. More... | |
List< Json_table_column > | m_vt_list |
List of fields for tmp table creation. More... | |
List< Json_table_column > * | m_columns |
Tree of COLUMN clauses. More... | |
Mem_root_array< Json_table_column * > | m_all_columns |
Array of all columns - the flattened tree above. More... | |
const char * | m_table_alias |
JSON_TABLE's alias, for error reporting. More... | |
bool | is_source_parsed |
Whether source data has been parsed. More... | |
Item * | source |
JSON_TABLE's data source expression. More... | |
Additional Inherited Members | |
Protected Attributes inherited from Table_function | |
TABLE * | table |
Table function's result table. More... | |
bool | inited |
Whether the table function was already initialized. More... | |
Table_function_json::Table_function_json | ( | const char * | alias, |
Item * | a, | ||
List< Json_table_column > * | cols | ||
) |
|
inlineoverride |
|
overrideprivatevirtual |
Reimplemented from Table_function.
|
overrideprivatevirtual |
Check whether given default values can be saved to fields.
Implements Table_function.
|
private |
Fill the result table.
Fill json table.
This function goes along the flattened list of columns and updates them by calling fill_column(). As it goes, it pushes all nested path nodes to 'nested' list, using it as a stack. After writing a row, it checks whether there's more data in the right-most nested path (top in the stack). If there is, it advances path's iterator, if no - pops the path from stack and goes to the next nested path (i.e more to left). When stack is empty, then the loop is over and all data (if any) was stored in the table, and function exits. Otherwise, the list of columns is positioned to the top nested path in the stack and incremented to the column after the nested path, then the loop of updating columns is executed again. So, whole execution could look as follows:
columns ( <-- npr cr1, cr2, nested path .. columns ( <-- np1 c11, nested path .. columns ( <-- np2 c21 ) ) ) iteration | columns updated in the loop 1 npr cr1 cr2 np1 c11 np2 c21 2 c21 3 c21 4 c11 np2 c21 5 c21 6 c11 np2 c21 7 c21 8 npr cr1 cr2 np1 c11 np2 c21 9 c21
10 c11 np2 c21 Note that result table's row isn't automatically reset and if a column isn't updated, its data is written multiple times. E.g. cr1 in the example above is updated 2 times, but is written 10 times. This allows to save cycles on updating fields that for sure haven't been changed.
When there's sibling nested paths, i.e two or more nested paths in the same columns clause, then they're processed one at a time. Started with first, and the rest are set to null with help f set_subtree_to_null(). When the first sibling nested path runs out of rows, it's set to null and processing moves on to the next one.
|
overridevirtual |
|
inlineoverridevirtual |
Returns function's name.
Implements Table_function.
|
overrideprivatevirtual |
Return list of fields to create result table from.
Implements Table_function.
|
overridevirtual |
Initialize the table function before creation of result table.
Implements Table_function.
|
private |
Initialize columns and lists for json table.
This function does several things: 1) sets up list of fields (vt_list) for result table creation 2) fills array of all columns (m_all_columns) for execution 3) for each column that has default ON EMPTY or ON ERROR clauses, checks the value to be proper json and initializes column appropriately 4) for each column that involves path, the path is checked to be correct. The function goes recursively, starting from the top NESTED PATH clause and going in the depth-first way, traverses the tree of columns.
nest_idx | index of parent's element in the nesting data array |
parent | Parent of the NESTED PATH clause being initialized |
|
overridevirtual |
JSON_TABLE printout.
thd | thread handler |
str | string to print to |
query_type | type of query |
Implements Table_function.
|
private |
A helper function which sets all columns under given NESTED PATH column to nullptr.
Used to evaluate sibling NESTED PATHS.
root | root NESTED PATH column | |
[out] | last | last column which belongs to the given NESTED PATH |
|
overridevirtual |
Return table_map of tables used by function's data source.
Reimplemented from Table_function.
|
overridevirtual |
Implements Table_function.
|
private |
Whether source data has been parsed.
|
private |
Array of all columns - the flattened tree above.
|
private |
Tree of COLUMN clauses.
|
private |
Array of JSON Data Source for each NESTED PATH clause.
|
private |
JSON_TABLE's alias, for error reporting.
|
private |
List of fields for tmp table creation.
|
private |
JSON_TABLE's data source expression.