MCPcopy Create free account
hub / github.com/Meituan-Dianping/SQLAdvisor / mysql_new_select

Function mysql_new_select

sql/sql_parse.cc:1004–1090  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1002*/
1003
1004bool
1005mysql_new_select(LEX *lex, bool move_down)
1006{
1007 SELECT_LEX *select_lex;
1008 THD *thd= lex->thd;
1009 Name_resolution_context *outer_context= lex->current_context();
1010 DBUG_ENTER("mysql_new_select");
1011
1012 if (!(select_lex= new (thd->mem_root) SELECT_LEX()))
1013 DBUG_RETURN(1);
1014 select_lex->select_number= ++thd->select_number;
1015 select_lex->parent_lex= lex; /* Used in init_query. */
1016 select_lex->init_query();
1017 select_lex->init_select();
1018 lex->nest_level++;
1019 if (lex->nest_level > (int) MAX_SELECT_NESTING)
1020 {
1021 my_error(ER_TOO_HIGH_LEVEL_OF_NESTING_FOR_SELECT, MYF(0));
1022 DBUG_RETURN(1);
1023 }
1024 select_lex->nest_level= lex->nest_level;
1025 if (move_down)
1026 {
1027 SELECT_LEX_UNIT *unit;
1028 lex->subqueries= TRUE;
1029 /* first select_lex of subselect or derived table */
1030 if (!(unit= new (thd->mem_root) SELECT_LEX_UNIT()))
1031 DBUG_RETURN(1);
1032
1033 unit->init_query();
1034 unit->init_select();
1035 unit->thd= thd;
1036 unit->include_down(lex->current_select);
1037 unit->link_next= 0;
1038 unit->link_prev= 0;
1039 select_lex->include_down(unit);
1040 /*
1041 By default we assume that it is usual subselect and we have outer name
1042 resolution context, if no we will assign it to 0 later
1043 */
1044 if (select_lex->outer_select()->parsing_place == IN_ON)
1045 /*
1046 This subquery is part of an ON clause, so we need to link the
1047 name resolution context for this subquery with the ON context.
1048
1049 @todo outer_context is not the same as
1050 &select_lex->outer_select()->context in one case:
1051 (SELECT 1 as a) UNION (SELECT 2) ORDER BY (SELECT a);
1052 When we create the select_lex for the subquery in ORDER BY,
1053 1) outer_context is the context of the second SELECT of the
1054 UNION
1055 2) &select_lex->outer_select() is the fake select_lex, which context
1056 is the one of the first SELECT of the UNION (see
1057 st_select_lex_unit::add_fake_select_lex()).
1058 2) is the correct context, per the documentation. 1) is not, and using
1059 it leads to a resolving error for the query above.
1060 We should fix 1) and then use it unconditionally here.
1061 */

Callers

nothing calls this directly

Calls 11

my_errorFunction · 0.85
current_contextMethod · 0.80
init_queryMethod · 0.80
init_selectMethod · 0.80
include_downMethod · 0.80
outer_selectMethod · 0.80
include_neighbourMethod · 0.80
master_unitMethod · 0.80
add_fake_select_lexMethod · 0.80
first_selectMethod · 0.80
include_globalMethod · 0.80

Tested by

no test coverage detected