Commit 2656e876 authored by Sergei Petrunia's avatar Sergei Petrunia

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.
parent 3f138fa3
......@@ -491,7 +491,7 @@ class Json_writer_object : public Json_writer_struct
if (my_writer)
{
add_member("select_id");
if (unlikely(select_number >= INT_MAX))
if (unlikely(select_number == FAKE_SELECT_LEX_ID))
context.add_str("fake");
else
context.add_ll(static_cast<longlong>(select_number));
......
......@@ -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;
......@@ -108,7 +108,7 @@ class Explain_node : public Sql_alloc
};
virtual enum explain_node_type get_type()= 0;
virtual int get_select_id()= 0;
virtual uint get_select_id()= 0;
/**
expression cache statistics
......@@ -166,9 +166,9 @@ class Explain_basic_join : public Explain_node
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,
uint8 explain_flags, bool is_analyze);
......@@ -352,7 +352,7 @@ class Explain_union : public Explain_node
enum explain_node_type get_type() { return EXPLAIN_UNION; }
unit_common_op operation;
int get_select_id()
uint get_select_id()
{
DBUG_ASSERT(union_members.elements() > 0);
return union_members.at(0);
......@@ -879,7 +879,7 @@ class Explain_update : public Explain_node
{}
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;
......@@ -959,7 +959,7 @@ class Explain_insert : public Explain_node
StringBuffer<64> table_name;
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,
uint8 explain_flags, bool is_analyze);
......@@ -986,7 +986,7 @@ class Explain_delete: public Explain_update
bool deleting_all_rows;
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,
uint8 explain_flags, bool is_analyze);
......
......@@ -8954,7 +8954,7 @@ bool st_select_lex_unit::add_fake_select_lex(THD *thd_arg)
DBUG_RETURN(1);
fake_select_lex->include_standalone(this,
(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->make_empty_select();
fake_select_lex->set_linkage(GLOBAL_OPTIONS_TYPE);
......
......@@ -1585,7 +1585,7 @@ bool JOIN::build_explain()
JOIN_TAB *curr_tab= join_tab + exec_join_tab_cnt();
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 */
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
same SELECT
*/
DBUG_ASSERT(select_lex->select_number == UINT_MAX ||
select_lex->select_number == INT_MAX || !output ||
DBUG_ASSERT(select_lex->select_number == FAKE_SELECT_LEX_ID || !output ||
!output->get_select(select_lex->select_number) ||
output->get_select(select_lex->select_number)->select_lex ==
select_lex);
if (select_lex->select_number != UINT_MAX &&
select_lex->select_number != INT_MAX /* this is not a UNION's "fake select */ &&
if (select_lex->select_number != FAKE_SELECT_LEX_ID &&
have_query_plan != JOIN::QEP_NOT_PRESENT_YET &&
have_query_plan != JOIN::QEP_DELETED && // this happens when there was
// 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) &&
thd->lex->all_selects_list &&
thd->lex->all_selects_list->link_next &&
select_number != UINT_MAX &&
select_number != INT_MAX)
select_number != FAKE_SELECT_LEX_ID)
{
str->append("/* select#");
str->append_ulonglong(select_number);
......
......@@ -397,8 +397,7 @@ bool table_value_constr::optimize(THD *thd)
create_explain_query_if_not_exists(thd->lex, thd->mem_root);
have_query_plan= QEP_AVAILABLE;
if (select_lex->select_number != UINT_MAX &&
select_lex->select_number != INT_MAX /* this is not a UNION's "fake select */ &&
if (select_lex->select_number != FAKE_SELECT_LEX_ID &&
have_query_plan != QEP_NOT_PRESENT_YET &&
thd->lex->explain && // for "SET" command in SPs.
(!thd->lex->explain->get_select(select_lex->select_number)))
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment