summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSergei Petrunia <psergey@askmonty.org>2021-04-15 00:19:13 +0300
committerSergei Petrunia <psergey@askmonty.org>2021-04-17 00:05:29 +0300
commit2656e876828c2d3cb05bd698fc641e333c336034 (patch)
tree7164aca065740925f5c47b2413cda3564eae64b0
parent3f138fa3a53383b98a934aae72667390ea3bf2eb (diff)
downloadmariadb-git-2656e876828c2d3cb05bd698fc641e333c336034.tar.gz
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.
-rw-r--r--sql/my_json_writer.h2
-rw-r--r--sql/sql_explain.h16
-rw-r--r--sql/sql_parse.cc2
-rw-r--r--sql/sql_select.cc11
-rw-r--r--sql/sql_tvc.cc3
5 files changed, 15 insertions, 19 deletions
diff --git a/sql/my_json_writer.h b/sql/my_json_writer.h
index bc8002de529..27aec74d08d 100644
--- a/sql/my_json_writer.h
+++ b/sql/my_json_writer.h
@@ -491,7 +491,7 @@ public:
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));
diff --git a/sql/sql_explain.h b/sql/sql_explain.h
index 9090416847f..42590e0bea0 100644
--- a/sql/sql_explain.h
+++ b/sql/sql_explain.h
@@ -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 @@ public:
};
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 @@ public:
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 @@ public:
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 @@ public:
{}
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 @@ public:
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 @@ public:
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);
diff --git a/sql/sql_parse.cc b/sql/sql_parse.cc
index 3f0e71c747f..ddfc49c6d52 100644
--- a/sql/sql_parse.cc
+++ b/sql/sql_parse.cc
@@ -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);
diff --git a/sql/sql_select.cc b/sql/sql_select.cc
index dacd636985a..5f974397b10 100644
--- a/sql/sql_select.cc
+++ b/sql/sql_select.cc
@@ -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);
diff --git a/sql/sql_tvc.cc b/sql/sql_tvc.cc
index 6984fdd6bcf..576927ea086 100644
--- a/sql/sql_tvc.cc
+++ b/sql/sql_tvc.cc
@@ -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)))