1
0
mirror of https://github.com/MariaDB/server.git synced 2025-08-08 11:22:35 +03:00

Cleanup: fake_select_lex->select_number=FAKE_SELECT_LEX_ID, not [U]INT_MAX

SELECT_LEX objects that are "fake_select_lex" (i.e read UNION output)
used both INT_MAX and UINT_MAX as select_number.
- mysql_explain_union() assigned UINT_MAX
- st_select_lex_unit::add_fake_select_lex assigned INT_MAX

This didn't matter initially (before EXPLAIN FORMAT=JSON), because the
code  had no checks for this value.

EXPLAIN FORMAT=JSON and later other features did introduce checks for
select_number values. The check had to check for two constants and
looked really confusing.

This patch joins the two constants into one - FAKE_SELECT_LEX_ID.
This commit is contained in:
Sergei Petrunia
2021-04-15 00:19:13 +03:00
parent 3f138fa3a5
commit 2656e87682
5 changed files with 15 additions and 19 deletions

View File

@@ -491,7 +491,7 @@ public:
if (my_writer) if (my_writer)
{ {
add_member("select_id"); add_member("select_id");
if (unlikely(select_number >= INT_MAX)) if (unlikely(select_number == FAKE_SELECT_LEX_ID))
context.add_str("fake"); context.add_str("fake");
else else
context.add_ll(static_cast<longlong>(select_number)); context.add_ll(static_cast<longlong>(select_number));

View File

@@ -74,7 +74,7 @@ class Json_writer;
*************************************************************************************/ *************************************************************************************/
const int FAKE_SELECT_LEX_ID= (int)UINT_MAX; const uint FAKE_SELECT_LEX_ID= UINT_MAX;
class Explain_query; class Explain_query;
@@ -108,7 +108,7 @@ public:
}; };
virtual enum explain_node_type get_type()= 0; virtual enum explain_node_type get_type()= 0;
virtual int get_select_id()= 0; virtual uint get_select_id()= 0;
/** /**
expression cache statistics expression cache statistics
@@ -166,9 +166,9 @@ public:
bool add_table(Explain_table_access *tab, Explain_query *query); bool add_table(Explain_table_access *tab, Explain_query *query);
int get_select_id() { return select_id; } uint get_select_id() { return select_id; }
int select_id; uint select_id;
int print_explain(Explain_query *query, select_result_sink *output, int print_explain(Explain_query *query, select_result_sink *output,
uint8 explain_flags, bool is_analyze); uint8 explain_flags, bool is_analyze);
@@ -352,7 +352,7 @@ public:
enum explain_node_type get_type() { return EXPLAIN_UNION; } enum explain_node_type get_type() { return EXPLAIN_UNION; }
unit_common_op operation; unit_common_op operation;
int get_select_id() uint get_select_id()
{ {
DBUG_ASSERT(union_members.elements() > 0); DBUG_ASSERT(union_members.elements() > 0);
return union_members.at(0); return union_members.at(0);
@@ -879,7 +879,7 @@ public:
{} {}
virtual enum explain_node_type get_type() { return EXPLAIN_UPDATE; } virtual enum explain_node_type get_type() { return EXPLAIN_UPDATE; }
virtual int get_select_id() { return 1; /* always root */ } virtual uint get_select_id() { return 1; /* always root */ }
const char *select_type; const char *select_type;
@@ -959,7 +959,7 @@ public:
StringBuffer<64> table_name; StringBuffer<64> table_name;
enum explain_node_type get_type() { return EXPLAIN_INSERT; } enum explain_node_type get_type() { return EXPLAIN_INSERT; }
int get_select_id() { return 1; /* always root */ } uint get_select_id() { return 1; /* always root */ }
int print_explain(Explain_query *query, select_result_sink *output, int print_explain(Explain_query *query, select_result_sink *output,
uint8 explain_flags, bool is_analyze); uint8 explain_flags, bool is_analyze);
@@ -986,7 +986,7 @@ public:
bool deleting_all_rows; bool deleting_all_rows;
virtual enum explain_node_type get_type() { return EXPLAIN_DELETE; } virtual enum explain_node_type get_type() { return EXPLAIN_DELETE; }
virtual int get_select_id() { return 1; /* always root */ } virtual uint get_select_id() { return 1; /* always root */ }
virtual int print_explain(Explain_query *query, select_result_sink *output, virtual int print_explain(Explain_query *query, select_result_sink *output,
uint8 explain_flags, bool is_analyze); uint8 explain_flags, bool is_analyze);

View File

@@ -8954,7 +8954,7 @@ bool st_select_lex_unit::add_fake_select_lex(THD *thd_arg)
DBUG_RETURN(1); DBUG_RETURN(1);
fake_select_lex->include_standalone(this, fake_select_lex->include_standalone(this,
(SELECT_LEX_NODE**)&fake_select_lex); (SELECT_LEX_NODE**)&fake_select_lex);
fake_select_lex->select_number= INT_MAX; fake_select_lex->select_number= FAKE_SELECT_LEX_ID;
fake_select_lex->parent_lex= thd_arg->lex; /* Used in init_query. */ fake_select_lex->parent_lex= thd_arg->lex; /* Used in init_query. */
fake_select_lex->make_empty_select(); fake_select_lex->make_empty_select();
fake_select_lex->set_linkage(GLOBAL_OPTIONS_TYPE); fake_select_lex->set_linkage(GLOBAL_OPTIONS_TYPE);

View File

@@ -1585,7 +1585,7 @@ bool JOIN::build_explain()
JOIN_TAB *curr_tab= join_tab + exec_join_tab_cnt(); JOIN_TAB *curr_tab= join_tab + exec_join_tab_cnt();
for (uint i= 0; i < aggr_tables; i++, curr_tab++) for (uint i= 0; i < aggr_tables; i++, curr_tab++)
{ {
if (select_nr == INT_MAX) if (select_nr == FAKE_SELECT_LEX_ID)
{ {
/* this is a fake_select_lex of a union */ /* this is a fake_select_lex of a union */
select_nr= select_lex->master_unit()->first_select()->select_number; select_nr= select_lex->master_unit()->first_select()->select_number;
@@ -4208,14 +4208,12 @@ bool JOIN::save_explain_data(Explain_query *output, bool can_overwrite,
If there is SELECT in this statement with the same number it must be the If there is SELECT in this statement with the same number it must be the
same SELECT same SELECT
*/ */
DBUG_ASSERT(select_lex->select_number == UINT_MAX || DBUG_ASSERT(select_lex->select_number == FAKE_SELECT_LEX_ID || !output ||
select_lex->select_number == INT_MAX || !output ||
!output->get_select(select_lex->select_number) || !output->get_select(select_lex->select_number) ||
output->get_select(select_lex->select_number)->select_lex == output->get_select(select_lex->select_number)->select_lex ==
select_lex); select_lex);
if (select_lex->select_number != UINT_MAX && if (select_lex->select_number != FAKE_SELECT_LEX_ID &&
select_lex->select_number != INT_MAX /* this is not a UNION's "fake select */ &&
have_query_plan != JOIN::QEP_NOT_PRESENT_YET && have_query_plan != JOIN::QEP_NOT_PRESENT_YET &&
have_query_plan != JOIN::QEP_DELETED && // this happens when there was have_query_plan != JOIN::QEP_DELETED && // this happens when there was
// no QEP ever, but then // no QEP ever, but then
@@ -27780,8 +27778,7 @@ void st_select_lex::print(THD *thd, String *str, enum_query_type query_type)
if ((query_type & QT_SHOW_SELECT_NUMBER) && if ((query_type & QT_SHOW_SELECT_NUMBER) &&
thd->lex->all_selects_list && thd->lex->all_selects_list &&
thd->lex->all_selects_list->link_next && thd->lex->all_selects_list->link_next &&
select_number != UINT_MAX && select_number != FAKE_SELECT_LEX_ID)
select_number != INT_MAX)
{ {
str->append("/* select#"); str->append("/* select#");
str->append_ulonglong(select_number); str->append_ulonglong(select_number);

View File

@@ -397,8 +397,7 @@ bool table_value_constr::optimize(THD *thd)
create_explain_query_if_not_exists(thd->lex, thd->mem_root); create_explain_query_if_not_exists(thd->lex, thd->mem_root);
have_query_plan= QEP_AVAILABLE; have_query_plan= QEP_AVAILABLE;
if (select_lex->select_number != UINT_MAX && if (select_lex->select_number != FAKE_SELECT_LEX_ID &&
select_lex->select_number != INT_MAX /* this is not a UNION's "fake select */ &&
have_query_plan != QEP_NOT_PRESENT_YET && have_query_plan != QEP_NOT_PRESENT_YET &&
thd->lex->explain && // for "SET" command in SPs. thd->lex->explain && // for "SET" command in SPs.
(!thd->lex->explain->get_select(select_lex->select_number))) (!thd->lex->explain->get_select(select_lex->select_number)))