Commit 45f098bf authored by bell@sanja.is.com.ua's avatar bell@sanja.is.com.ua

moved similar code to function

onversion with check
parent bb49de5f
......@@ -463,27 +463,7 @@ bool Item_field::fix_fields(THD *thd, TABLE_LIST *tables, Item **ref)
Mark all selects from resolved to 1 before select where was
found table as depended (of select where was found table)
*/
for (SELECT_LEX_NODE *s= thd->lex.current_select;
s && s != last;
s= s->outer_select())
{
if( !s->dependent)
{
// Select is depended of outer select
s->dependent= 1;
if (s->linkage != GLOBAL_OPTIONS_TYPE)
{
//s is st_select_lex*
s->master_unit()->dependent= 1;
//Tables will be reopened many times
for (TABLE_LIST *tbl= s->get_table_list();
tbl;
tbl= tbl->next)
tbl->shared= 1;
}
}
}
thd->lex.current_select->mark_as_dependent(last);
}
}
else if (!tmp)
......@@ -867,30 +847,7 @@ bool Item_ref::fix_fields(THD *thd,TABLE_LIST *tables, Item **reference)
else
{
depended_from= last;
/*
Mark all selects from resolved to 1 before select where was
found table as depended (of select where was found table)
*/
for (SELECT_LEX_NODE *s= thd->lex.current_select;
s &&s != last;
s= s->outer_select())
if( !s->dependent )
{
// Select is depended of outer select
s->dependent= 1;
if (s->linkage != GLOBAL_OPTIONS_TYPE)
{
//s is st_select_lex*
s->master_unit()->dependent= 1;
//Tables will be reopened many times
for (TABLE_LIST *tbl=
s->get_table_list();
tbl;
tbl= tbl->next)
tbl->shared= 1;
}
}
thd->lex.current_select->mark_as_dependent(last);
}
}
else if (!ref)
......
......@@ -943,7 +943,7 @@ bool Item_sum_count_distinct::fix_fields(THD *thd, TABLE_LIST *tables,
bool Item_sum_count_distinct::setup(THD *thd)
{
List<Item> list;
SELECT_LEX *select_lex= (SELECT_LEX *)current_lex->current_select;
SELECT_LEX *select_lex= current_lex->current_select->select_lex();
if (select_lex->linkage == GLOBAL_OPTIONS_TYPE)
return 1;
......
......@@ -285,11 +285,7 @@ multi_delete::initialize_tables(JOIN *join)
table->file->ref_length,
MEM_STRIP_BUF_SIZE);
}
/*
There are (SELECT_LEX*) pointer conversion here global union parameters
can't be used in multidelete
*/
init_ftfuncs(thd, (SELECT_LEX*)thd->lex.current_select, 1);
init_ftfuncs(thd, thd->lex.current_select->select_lex(), 1);
}
......
......@@ -57,7 +57,7 @@ int mysql_derived(THD *thd, LEX *lex, SELECT_LEX_UNIT *unit, TABLE_LIST *t,
{
if (cursor->derived)
{
res=mysql_derived(thd, lex, (SELECT_LEX_UNIT *)cursor->derived,
res= mysql_derived(thd, lex, (SELECT_LEX_UNIT *)cursor->derived,
cursor, 0);
if (res) DBUG_RETURN(res);
}
......
......@@ -21,6 +21,7 @@
#include "item_create.h"
#include <m_ctype.h>
#include <hash.h>
#include <assert.h>
LEX_STRING tmp_table_alias= {(char*) "tmp-table",8};
......@@ -1043,6 +1044,13 @@ void st_select_lex_node::exclude()
*/
}
st_select_lex* st_select_lex_node::select_lex()
{
DBUG_ENTER("st_select_lex_node::select_lex (never should be called)");
DBUG_ASSERT(1);
DBUG_RETURN(0);
}
bool st_select_lex_node::add_item_to_list(Item *item)
{
return 1;
......@@ -1053,7 +1061,6 @@ bool st_select_lex_node::add_group_to_list(Item *item, bool asc)
return 1;
}
//why compiler/linker do not allow make it inline?
bool st_select_lex_node::add_order_to_list(Item *item, bool asc)
{
return add_to_list(order_list,item,asc);
......@@ -1064,6 +1071,47 @@ bool st_select_lex_node::add_ftfunc_to_list(Item_func_match *func)
return 1;
}
/*
st_select_lex_node::mark_as_dependent mark all st_select_lex struct from
this to 'last' as dependent
SYNOPSIS
last - pointer to last st_select_lex struct, before wich all
st_select_lex have to be marked as dependent
NOTE
'last' should be reachable from this st_select_lex_node
*/
void st_select_lex_node::mark_as_dependent(SELECT_LEX *last)
{
/*
Mark all selects from resolved to 1 before select where was
found table as depended (of select where was found table)
*/
for (SELECT_LEX_NODE *s= this;
s &&s != last;
s= s->outer_select())
if( !s->dependent )
{
// Select is dependent of outer select
s->dependent= 1;
if (s->linkage != GLOBAL_OPTIONS_TYPE)
{
//s is st_select_lex*
s->master_unit()->dependent= 1;
//Tables will be reopened many times
for (TABLE_LIST *tbl=
s->get_table_list();
tbl;
tbl= tbl->next)
tbl->shared= 1;
}
}
}
bool st_select_lex_node::set_braces(bool value) { return 1; }
bool st_select_lex_node::inc_in_sum_expr() { return 1; }
uint st_select_lex_node::get_in_sum_expr() { return 0; }
......@@ -1168,6 +1216,10 @@ st_select_lex* st_select_lex_unit::outer_select()
return (st_select_lex*) master;
}
st_select_lex* st_select_lex::select_lex()
{
return this;
}
bool st_select_lex::add_item_to_list(Item *item)
{
......
......@@ -217,6 +217,7 @@ public:
void include_global(st_select_lex_node **plink);
void exclude();
virtual st_select_lex* select_lex();
virtual bool add_item_to_list(Item *item);
bool add_order_to_list(Item *item, bool asc);
virtual bool add_group_to_list(Item *item, bool asc);
......@@ -239,6 +240,7 @@ public:
List<String> *use_index= 0,
List<String> *ignore_index= 0);
void mark_as_dependent(st_select_lex *last);
private:
void fast_exclude();
};
......@@ -346,6 +348,8 @@ public:
bool set_braces(bool value);
bool inc_in_sum_expr();
uint get_in_sum_expr();
st_select_lex* select_lex();
bool add_item_to_list(Item *item);
bool add_group_to_list(Item *item, bool asc);
bool add_ftfunc_to_list(Item_func_match *func);
......
......@@ -2927,7 +2927,7 @@ mysql_init_query(THD *thd)
void
mysql_init_select(LEX *lex)
{
SELECT_LEX *select_lex= (SELECT_LEX *)lex->current_select;
SELECT_LEX *select_lex= lex->current_select->select_lex();
DBUG_ASSERT(select_lex->linkage != GLOBAL_OPTIONS_TYPE);
select_lex->init_select();
select_lex->master_unit()->select_limit= select_lex->select_limit=
......@@ -2964,7 +2964,7 @@ mysql_new_select(LEX *lex, bool move_down)
select_lex->master_unit()->global_parameters= select_lex;
DBUG_ASSERT(lex->current_select->linkage != GLOBAL_OPTIONS_TYPE);
select_lex->include_global(((SELECT_LEX*)lex->current_select)->
select_lex->include_global(lex->current_select->select_lex()->
next_select_in_list_addr());
lex->current_select= select_lex;
return 0;
......
......@@ -508,14 +508,7 @@ multi_update::prepare(List<Item> &values, SELECT_LEX_UNIT *u)
counter++;
}
}
/*
There are (SELECT_LEX*) pointer conversion here global union parameters
can't be used in multiupdate
TODO: check is thd->lex.current_select == &thd->lex.select_lex?
*/
init_ftfuncs(thd, (SELECT_LEX*)thd->lex.current_select, 1);
init_ftfuncs(thd, thd->lex.current_select->select_lex(), 1);
error = 0; // Timestamps do not need to be restored, so far ...
DBUG_RETURN(0);
}
......
......@@ -2215,11 +2215,7 @@ in_sum_expr:
}
expr
{
/*
There are (SELECT_LEX *) pointer conversionis here, because
global union parameters checked in 'increment' above
*/
((SELECT_LEX *)Select)->in_sum_expr--;
Select->select_lex()->in_sum_expr--;
$$=$2;
};
......@@ -2296,12 +2292,7 @@ join_table_list:
{ add_join_on($4,$6); $$=$4; }
| join_table_list INNER_SYM JOIN_SYM join_table_list
{
/*
There are (SELECT_LEX *) pointer conversionis here and
following joins, because it is impossible FROM clause in
global union parameters
*/
SELECT_LEX *sel= (SELECT_LEX *)Select;
SELECT_LEX *sel= Select->select_lex();
sel->db1=$1->db; sel->table1=$1->alias;
sel->db2=$4->db; sel->table2=$4->alias;
}
......@@ -2311,7 +2302,7 @@ join_table_list:
{ add_join_on($5,$7); $5->outer_join|=JOIN_TYPE_LEFT; $$=$5; }
| join_table_list LEFT opt_outer JOIN_SYM join_table_list
{
SELECT_LEX *sel= (SELECT_LEX *)Select;
SELECT_LEX *sel= Select->select_lex();
sel->db1=$1->db; sel->table1=$1->alias;
sel->db2=$5->db; sel->table2=$5->alias;
}
......@@ -2323,7 +2314,7 @@ join_table_list:
{ add_join_on($1,$7); $1->outer_join|=JOIN_TYPE_RIGHT; $$=$1; }
| join_table_list RIGHT opt_outer JOIN_SYM join_table_list
{
SELECT_LEX *sel= (SELECT_LEX *)Select;
SELECT_LEX *sel= Select->select_lex();
sel->db1=$1->db; sel->table1=$1->alias;
sel->db2=$5->db; sel->table2=$5->alias;
}
......@@ -2341,7 +2332,7 @@ normal_join:
join_table:
{
SELECT_LEX *sel= (SELECT_LEX *)Select;
SELECT_LEX *sel= Select->select_lex();
sel->use_index_ptr=sel->ignore_index_ptr=0;
}
table_ident opt_table_alias opt_key_definition
......@@ -2388,45 +2379,40 @@ opt_key_definition:
/* empty */ {}
| USE_SYM key_usage_list
{
/*
There are (SELECT_LEX *) pointer conversionis here and
following key definitions, because
key definitions is impossible in union global parameters
*/
SELECT_LEX *sel= (SELECT_LEX*)Select;
SELECT_LEX *sel= Select->select_lex();
sel->use_index= *$2;
sel->use_index_ptr= &sel->use_index;
}
| IGNORE_SYM key_usage_list
{
SELECT_LEX *sel= (SELECT_LEX*)Select;
SELECT_LEX *sel= Select->select_lex();
sel->ignore_index= *$2;
sel->ignore_index_ptr= &sel->ignore_index;
};
key_usage_list:
key_or_index { ((SELECT_LEX *)Select)->interval_list.empty(); }
key_or_index { Select->select_lex()->interval_list.empty(); }
'(' key_usage_list2 ')'
{ $$= &((SELECT_LEX *)Select)->interval_list; };
{ $$= &Select->select_lex()->interval_list; };
key_usage_list2:
key_usage_list2 ',' ident
{ ((SELECT_LEX *)Select)->
{ Select->select_lex()->
interval_list.push_back(new String((const char*) $3.str, $3.length,
default_charset_info)); }
| ident
{ ((SELECT_LEX *)Select)->
{ Select->select_lex()->
interval_list.push_back(new String((const char*) $1.str, $1.length,
default_charset_info)); }
| PRIMARY_SYM
{ ((SELECT_LEX *)Select)->
{ Select->select_lex()->
interval_list.push_back(new String("PRIMARY", 7,
default_charset_info)); };
using_list:
ident
{
SELECT_LEX *sel= (SELECT_LEX *)Select;
SELECT_LEX *sel= Select->select_lex();
if (!($$= new Item_func_eq(new Item_field(sel->db1, sel->table1,
$1.str),
new Item_field(sel->db2, sel->table2,
......@@ -2435,7 +2421,7 @@ using_list:
}
| using_list ',' ident
{
SELECT_LEX *sel= (SELECT_LEX *)Select;
SELECT_LEX *sel= Select->select_lex();
if (!($$= new Item_cond_and(new Item_func_eq(new Item_field(sel->db1,sel->table1,$3.str), new Item_field(sel->db2,sel->table2,$3.str)), $1)))
YYABORT;
};
......@@ -2467,22 +2453,14 @@ opt_table_alias:
where_clause:
/*
There are (SELECT_LEX *) pointer conversionis here, because
it is impossible where_clause in global union parameters
*/
/* empty */ { ((SELECT_LEX *)Select)->where= 0; }
| WHERE expr { ((SELECT_LEX *)Select)->where= $2; };
/* empty */ { Select->select_lex()->where= 0; }
| WHERE expr { Select->select_lex()->where= $2; };
having_clause:
/*
There are (SELECT_LEX *) pointer conversionis here, because
it is impossible having_clause in global union parameters
*/
/* empty */
| HAVING { ((SELECT_LEX *)Select)->create_refs= 1; } expr
| HAVING { Select->select_lex()->create_refs= 1; } expr
{
SELECT_LEX *sel= (SELECT_LEX*)Select;
SELECT_LEX *sel= Select->select_lex();
sel->having= $3; sel->create_refs=0;
};
......@@ -2517,7 +2495,7 @@ olap_opt:
"global union parameters");
YYABORT;
}
((SELECT_LEX *)lex->current_select)->olap= CUBE_TYPE;
lex->current_select->select_lex()->olap= CUBE_TYPE;
net_printf(lex->thd, ER_NOT_SUPPORTED_YET, "CUBE");
YYABORT; /* To be deleted in 4.1 */
}
......@@ -2531,7 +2509,7 @@ olap_opt:
"global union parameters");
YYABORT;
}
((SELECT_LEX *)lex->current_select)->olap= ROLLUP_TYPE;
lex->current_select->select_lex()->olap= ROLLUP_TYPE;
net_printf(lex->thd, ER_NOT_SUPPORTED_YET, "ROLLUP");
YYABORT; /* To be deleted in 4.1 */
}
......@@ -2555,7 +2533,7 @@ order_clause:
YYABORT;
}
if (lex->current_select->linkage != GLOBAL_OPTIONS_TYPE &&
((SELECT_LEX*)lex->current_select)->olap !=
lex->current_select->select_lex()->olap !=
UNSPECIFIED_OLAP_TYPE)
{
net_printf(lex->thd, ER_WRONG_USAGE,
......@@ -2583,7 +2561,7 @@ limit_clause:
{
LEX *lex= Lex;
if (lex->current_select->linkage != GLOBAL_OPTIONS_TYPE &&
((SELECT_LEX*)lex->current_select)->olap !=
lex->current_select->select_lex()->olap !=
UNSPECIFIED_OLAP_TYPE)
{
net_printf(lex->thd, ER_WRONG_USAGE, "CUBE/ROLLUP",
......@@ -2598,7 +2576,7 @@ limit_clause:
{
LEX *lex=Lex;
if (lex->current_select->linkage != GLOBAL_OPTIONS_TYPE &&
((SELECT_LEX*)lex->current_select)->olap !=
lex->current_select->select_lex()->olap !=
UNSPECIFIED_OLAP_TYPE)
{
net_printf(lex->thd, ER_WRONG_USAGE, "CUBE/ROLLUP",
......@@ -4005,12 +3983,7 @@ opt_table:
'*'
{
LEX *lex= Lex;
/*
There are (SELECT_LEX *) pointer conversionis here and following
opt_table, because it is impossible GRANT clause in global
union parameters
*/
((SELECT_LEX *)lex->current_select)->db= lex->thd->db;
lex->current_select->select_lex()->db= lex->thd->db;
if (lex->grant == GLOBAL_ACLS)
lex->grant = DB_ACLS & ~GRANT_ACL;
else if (lex->columns.elements)
......@@ -4022,7 +3995,7 @@ opt_table:
| ident '.' '*'
{
LEX *lex= Lex;
((SELECT_LEX *)lex->current_select)->db = $1.str;
lex->current_select->select_lex()->db = $1.str;
if (lex->grant == GLOBAL_ACLS)
lex->grant = DB_ACLS & ~GRANT_ACL;
else if (lex->columns.elements)
......@@ -4034,7 +4007,7 @@ opt_table:
| '*' '.' '*'
{
LEX *lex= Lex;
((SELECT_LEX *)lex->current_select)->db = NULL;
lex->current_select->select_lex()->db = NULL;
if (lex->grant == GLOBAL_ACLS)
lex->grant= GLOBAL_ACLS & ~GRANT_ACL;
else if (lex->columns.elements)
......@@ -4227,7 +4200,7 @@ optional_order_or_limit:
send_error(lex->thd, ER_SYNTAX_ERROR);
YYABORT;
}
SELECT_LEX *sel= (SELECT_LEX *)lex->current_select;
SELECT_LEX *sel= lex->current_select->select_lex();
sel->master_unit()->global_parameters=
sel->master_unit();
lex->current_select= sel->master_unit();
......
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