MySQL 8.0.39
Source Code Documentation
dd::info_schema::Select_lex_builder Class Reference

This class provide framework to build a Query_block using ParseTree nodes. More...

#include <show_query_builder.h>

Public Member Functions

 Select_lex_builder (const POS *pc, THD *thd)
 
bool add_star_select_item ()
 Add item representing star in "SELECT '*' ...". More...
 
bool add_select_item (const LEX_CSTRING &field_name, const LEX_CSTRING &alias)
 Add item representing a column as,. More...
 
bool add_select_expr (Item *select_list_item, const LEX_CSTRING &alias)
 Add expression as an item tree, with an alias to name the resulting column. More...
 
bool add_from_item (const LEX_CSTRING &schema_name, const LEX_CSTRING &table_name)
 Add item representing a FROM clause table as,. More...
 
bool add_from_item (PT_derived_table *dt)
 Add item representing a FROM clause table as,. More...
 
Itemprepare_like_item (const LEX_CSTRING &field_name, const String *wild)
 Prepare item representing a LIKE condition,. More...
 
Itemprepare_equal_item (const LEX_CSTRING &field_name, const LEX_CSTRING &value)
 Prepare item representing a equal to comparison condition,. More...
 
bool add_condition (Item *a)
 Add a WHERE clause condition to Select_lex_builder. More...
 
bool add_order_by (const LEX_CSTRING &field_name)
 Add a ORDER BY clause field to Select_lex_builder. More...
 
PT_derived_tableprepare_derived_table (const LEX_CSTRING &table_alias)
 This function build ParseTree node that represents this Select_lex_builder as sub-query. More...
 
Query_blockprepare_query_block ()
 Prepare a Query_block using all the information information added to this Select_lex_builder. More...
 

Private Member Functions

bool add_to_select_item_list (Item *expr)
 Prepare a list of expression used to build select items for the query being built. More...
 

Private Attributes

const POSm_pos
 
THDm_thd
 
PT_select_item_listm_select_item_list
 
Mem_root_array_YY< PT_table_reference * > m_table_reference_list
 
Itemm_where_clause
 
PT_order_listm_order_by_list
 

Detailed Description

This class provide framework to build a Query_block using ParseTree nodes.

Note that this class is designed to help build queries that are required to implement SHOW commands over data dictionary tables. It does not provide complete framework, e.g., you cannot add a GROUP BY node for now, mainly because that is not needed to implement SHOW command.

This class is used by implementation of SHOW command in sql/dd/show.cc. The class enables code re-usability.

One can build Query_block that represents following,

... SELECT star_select_item, select_item1, select_item2, ... FROM from_item OR FROM PT_derived_table WHERE condition AND condition AND ... ORDER BY order_by_field1, order_by_field2 , ... ...

Where as, a 'condition' can be one of, field_name = "value" field_name LIKE "value%"

One can think of enhancing this framework on need basis.

Note to server general team: This framework can be used by sql/sql_show_status.* implementation. For now, this file is kept inside sql/dd, but we can think of moving it out to sql/.

The memory used while building the this Parse Tree is thd->mem_root.

Constructor & Destructor Documentation

◆ Select_lex_builder()

dd::info_schema::Select_lex_builder::Select_lex_builder ( const POS pc,
THD thd 
)

Member Function Documentation

◆ add_condition()

bool dd::info_schema::Select_lex_builder::add_condition ( Item a)

Add a WHERE clause condition to Select_lex_builder.

SELECT ... WHERE ... AND <condition> ...
const std::string SELECT("SELECT")
Name of the static privileges.
@ WHERE
Definition: sql_yacc.h:679

If there are existing conditions, then the new condition is append to the WHERE clause conditions with a 'AND' condition.

Returns
false on success. true on failure.

◆ add_from_item() [1/2]

bool dd::info_schema::Select_lex_builder::add_from_item ( const LEX_CSTRING schema_name,
const LEX_CSTRING table_name 
)

Add item representing a FROM clause table as,.

SELECT ... FROM <schema_name>.<table_name> ...
const char * table_name
Definition: rules_table_service.cc:56

Only single table can be added. We cannot build a query with JOIN clause for now.

Returns
false on success. true on failure.
SELECT ... FROM <schema_name>.<table_name> ...

◆ add_from_item() [2/2]

bool dd::info_schema::Select_lex_builder::add_from_item ( PT_derived_table dt)

Add item representing a FROM clause table as,.

SELECT ... FROM <sub query or derived table> ...

Only single table can be added. We cannot build a query with JOIN clause for now.

Returns
false on success. true on failure.
SELECT ... FROM <sub query or derived table> ...

◆ add_order_by()

bool dd::info_schema::Select_lex_builder::add_order_by ( const LEX_CSTRING field_name)

Add a ORDER BY clause field to Select_lex_builder.

SELECT ... ORDER BY <field_name>, ...
Definition: table.h:282

If there are existing ORDER BY field, then we append a new field to the ORDER BY clause. All the fields are added to be order in ascending order.

Returns
false on success. true on failure.

◆ add_select_expr()

bool dd::info_schema::Select_lex_builder::add_select_expr ( Item select_list_item,
const LEX_CSTRING alias 
)

Add expression as an item tree, with an alias to name the resulting column.

Add expression item representing a column as, "SELECT <expr> AS <alias>, ...".

The item will be appended to existing list of select items for this query block.

Returns
false on success. true on failure.

◆ add_select_item()

bool dd::info_schema::Select_lex_builder::add_select_item ( const LEX_CSTRING field_name,
const LEX_CSTRING alias 
)

Add item representing a column as,.

Add item representing a column as, "SELECT <field_name> AS <alias>, ...".

SELECT <field_name> AS <alias>, ...

The item will be appended to existing list of select items for this query.

Returns
false on success. true on failure.

◆ add_star_select_item()

bool dd::info_schema::Select_lex_builder::add_star_select_item ( )

Add item representing star in "SELECT '*' ...".

Returns
false on success. true on failure.

◆ add_to_select_item_list()

bool dd::info_schema::Select_lex_builder::add_to_select_item_list ( Item expr)
private

Prepare a list of expression used to build select items for the query being built.

Returns
false on success. true on failure.

◆ prepare_derived_table()

PT_derived_table * dd::info_schema::Select_lex_builder::prepare_derived_table ( const LEX_CSTRING table_alias)

This function build ParseTree node that represents this Select_lex_builder as sub-query.

This enables us to build a Query_block containing a sub-query in its FROM clause. This sub-query is represented by ParseTree node PT_derived_table.

SELECT ... FROM <PT_dervied_table>, ...
Returns
pointer to PT_derived_table on success. nullptr on failure.

◆ prepare_equal_item()

Item * dd::info_schema::Select_lex_builder::prepare_equal_item ( const LEX_CSTRING field_name,
const LEX_CSTRING value 
)

Prepare item representing a equal to comparison condition,.

SELECT ... WHERE <field_name> = <value> ...

This item should be intern added to Select_lex_builder using add_condition() method.

Returns
pointer to Item* on success. nullptr on failure.

◆ prepare_like_item()

Item * dd::info_schema::Select_lex_builder::prepare_like_item ( const LEX_CSTRING field_name,
const String wild 
)

Prepare item representing a LIKE condition,.

SELECT ... WHERE <field_name> LIKE <value%> ...

This item should be intern added to Select_lex_builder using add_condition() method.

Returns
pointer to Item* on success. nullptr on failure.

◆ prepare_query_block()

Query_block * dd::info_schema::Select_lex_builder::prepare_query_block ( )

Prepare a Query_block using all the information information added to this Select_lex_builder.

Returns
pointer to Query_block* on success. nullptr on failure.

Member Data Documentation

◆ m_order_by_list

PT_order_list* dd::info_schema::Select_lex_builder::m_order_by_list
private

◆ m_pos

const POS* dd::info_schema::Select_lex_builder::m_pos
private

◆ m_select_item_list

PT_select_item_list* dd::info_schema::Select_lex_builder::m_select_item_list
private

◆ m_table_reference_list

Mem_root_array_YY<PT_table_reference *> dd::info_schema::Select_lex_builder::m_table_reference_list
private

◆ m_thd

THD* dd::info_schema::Select_lex_builder::m_thd
private

◆ m_where_clause

Item* dd::info_schema::Select_lex_builder::m_where_clause
private

The documentation for this class was generated from the following files: