1261
1261
Exception is Item_direct_view_ref which we need to convert to
1262
1262
Item_ref to allow fields from view being stored in tmp table.
1264
Item_aggregate_ref *item_ref;
1264
1265
uint el= fields.elements;
1265
Item *new_item, *real_itm= real_item();
1266
Item *real_itm= real_item();
1267
1268
ref_pointer_array[el]= real_itm;
1268
if (!(new_item= new Item_aggregate_ref(&thd->lex->current_select->context,
1269
if (!(item_ref= new Item_aggregate_ref(&thd->lex->current_select->context,
1269
1270
ref_pointer_array + el, 0, name)))
1270
1271
return; // fatal_error is set
1272
if (type() == SUM_FUNC_ITEM)
1273
item_ref->depended_from= ((Item_sum *) this)->depended_from();
1271
1274
fields.push_front(real_itm);
1272
thd->change_item_tree(ref, new_item);
1275
thd->change_item_tree(ref, item_ref);
1607
1610
Item_field::Item_field(Field *f)
1608
1611
:Item_ident(0, NullS, *f->table_name, f->field_name),
1609
1612
item_equal(0), no_const_subst(0),
1610
have_privileges(0), any_privileges(0), fixed_as_field(0)
1613
have_privileges(0), any_privileges(0)
1622
1625
:Item_ident(context_arg, f->table->s->db, *f->table_name, f->field_name),
1623
1626
item_equal(0), no_const_subst(0),
1624
have_privileges(0), any_privileges(0), fixed_as_field(0)
1627
have_privileges(0), any_privileges(0)
1627
1630
We always need to provide Item_field with a fully qualified field
1660
1663
const char *field_name_arg)
1661
1664
:Item_ident(context_arg, db_arg,table_name_arg,field_name_arg),
1662
1665
field(0), result_field(0), item_equal(0), no_const_subst(0),
1663
have_privileges(0), any_privileges(0), fixed_as_field(0)
1666
have_privileges(0), any_privileges(0)
1665
1668
SELECT_LEX *select= current_thd->lex->current_select;
1666
1669
collation.set(DERIVATION_IMPLICIT);
1676
1679
item_equal(item->item_equal),
1677
1680
no_const_subst(item->no_const_subst),
1678
1681
have_privileges(item->have_privileges),
1679
any_privileges(item->any_privileges),
1680
fixed_as_field(item->fixed_as_field)
1682
any_privileges(item->any_privileges)
1682
1684
collation.set(DERIVATION_IMPLICIT);
2492
2494
item_result_type= REAL_RESULT;
2494
2496
case INT_RESULT:
2495
set_int(*(longlong*)entry->value, 21);
2497
set_int(*(longlong*)entry->value, MY_INT64_NUM_DECIMAL_DIGITS);
2496
2498
item_type= Item::INT_ITEM;
2497
2499
item_result_type= INT_RESULT;
3444
3446
Item **ref= (Item **) not_found_item;
3445
3447
SELECT_LEX *current_sel= (SELECT_LEX *) thd->lex->current_select;
3446
3448
Name_resolution_context *outer_context= 0;
3449
SELECT_LEX *select= 0;
3447
3450
/* Currently derived tables cannot be correlated */
3448
3451
if (current_sel->master_unit()->first_select()->linkage !=
3449
3452
DERIVED_TABLE_TYPE)
3453
3456
outer_context= outer_context->outer_context)
3455
SELECT_LEX *select= outer_context->select_lex;
3458
select= outer_context->select_lex;
3456
3459
Item_subselect *prev_subselect_item=
3457
3460
last_checked_context->select_lex->master_unit()->item;
3458
3461
last_checked_context= outer_context;
3496
3499
if (*from_field != view_ref_found)
3499
3501
prev_subselect_item->used_tables_cache|= (*from_field)->table->map;
3500
3502
prev_subselect_item->const_item_cache= 0;
3503
set_field(*from_field);
3501
3504
if (!last_checked_context->select_lex->having_fix_field &&
3505
select->group_list.elements)
3504
3507
Item_outer_ref *rf;
3505
Query_arena *arena= 0, backup;
3507
Each outer field is replaced for an Item_outer_ref object.
3508
This is done in order to get correct results when the outer
3509
select employs a temporary table.
3510
The original fields are saved in the inner_fields_list of the
3511
outer select. This list is created by the following reasons:
3512
1. We can't add field items to the outer select list directly
3513
because the outer select hasn't been fully fixed yet.
3514
2. We need a location to refer to in the Item_ref object
3515
so the inner_fields_list is used as such temporary
3517
The new Item_outer_ref object replaces the original field and is
3518
also saved in the inner_refs_list of the outer select. Here
3519
it is only created. It can be fixed only after the original
3520
field has been fixed and this is done in the fix_inner_refs()
3509
If an outer field is resolved in a grouping select then it
3510
is replaced for an Item_outer_ref object. Otherwise an
3511
Item_field object is used.
3512
The new Item_outer_ref object is saved in the inner_refs_list of
3513
the outer select. Here it is only created. It can be fixed only
3514
after the original field has been fixed and this is done in the
3515
fix_inner_refs() function.
3523
set_field(*from_field);
3524
arena= thd->activate_stmt_arena_if_needed(&backup);
3525
rf= new Item_outer_ref(context, this);
3529
thd->restore_active_arena(arena, &backup);
3518
if (!(rf= new Item_outer_ref(context, this)))
3520
thd->change_item_tree(reference, rf);
3533
3521
select->inner_refs_list.push_back(rf);
3535
thd->restore_active_arena(arena, &backup);
3522
rf->in_sum_func= thd->lex->in_sum_func;
3538
3524
if (thd->lex->in_sum_func &&
3539
3525
thd->lex->in_sum_func->nest_level ==
3639
3625
rf= (place == IN_HAVING ?
3640
3626
new Item_ref(context, ref, (char*) table_name,
3641
3627
(char*) field_name, alias_name_used) :
3628
(!select->group_list.elements ?
3642
3629
new Item_direct_ref(context, ref, (char*) table_name,
3643
(char*) field_name, alias_name_used));
3630
(char*) field_name, alias_name_used) :
3631
new Item_outer_ref(context, ref, (char*) table_name,
3632
(char*) field_name, alias_name_used)));
3637
if (place != IN_HAVING && select->group_list.elements)
3639
outer_context->select_lex->inner_refs_list.push_back((Item_outer_ref*)rf);
3640
((Item_outer_ref*)rf)->in_sum_func= thd->lex->in_sum_func;
3647
3642
thd->change_item_tree(reference, rf);
3649
3644
rf is Item_ref => never substitute other items (in this case)
4076
4071
The function returns a pointer to an item that is taken from
4077
4072
the very beginning of the item_equal list which the Item_field
4078
object refers to (belongs to).
4073
object refers to (belongs to) unless item_equal contains a constant
4074
item. In this case the function returns this constant item,
4075
(if the substitution does not require conversion).
4079
4076
If the Item_field object does not refer any Item_equal object
4080
4077
'this' is returned
4093
4091
if (item_equal)
4093
Item *const_item= item_equal->get_const();
4096
if (cmp_context != (Item_result)-1 &&
4097
const_item->cmp_context != cmp_context)
4095
4101
Item_field *subst= item_equal->get_first();
4096
4102
if (subst && !field->eq(subst->field))
4261
4267
case MYSQL_TYPE_MEDIUM_BLOB:
4262
4268
case MYSQL_TYPE_LONG_BLOB:
4263
4269
case MYSQL_TYPE_BLOB:
4264
case MYSQL_TYPE_GEOMETRY:
4265
4270
if (this->type() == Item::TYPE_HOLDER)
4266
4271
return new Field_blob(max_length, maybe_null, name, table,
4267
4272
collation.collation, 1);
4269
4274
return new Field_blob(max_length, maybe_null, name, table,
4270
4275
collation.collation);
4271
4276
break; // Blob handled outside of case
4277
case MYSQL_TYPE_GEOMETRY:
4278
return new Field_geom(max_length, maybe_null, name, table,
4279
(Field::geometry_type)
4280
((Item_geometry_func *)this)->get_geometry_type());
5534
5543
bool Item_outer_ref::fix_fields(THD *thd, Item **reference)
5537
/* outer_field->check_cols() will be made in Item_direct_ref::fix_fields */
5538
outer_field->fixed_as_field= 1;
5539
if (!outer_field->fixed &&
5540
(outer_field->fix_fields(thd, reference)))
5546
/* outer_ref->check_cols() will be made in Item_direct_ref::fix_fields */
5547
if ((*ref) && !(*ref)->fixed && ((*ref)->fix_fields(thd, reference)))
5542
table_name= outer_field->table_name;
5543
return Item_direct_ref::fix_fields(thd, reference);
5549
err= Item_direct_ref::fix_fields(thd, reference);
5552
if ((*ref)->type() == Item::FIELD_ITEM)
5553
table_name= ((Item_field*)outer_ref)->table_name;
5547
5559
Compare two view column references for equality.
6337
6349
:Item(thd, item), enum_set_typelib(0), fld_type(get_real_type(item))
6339
6351
DBUG_ASSERT(item->fixed);
6341
max_length= display_length(item);
6342
6352
maybe_null= item->maybe_null;
6343
6353
collation.set(item->collation);
6344
6354
get_full_info(item);
6511
6521
int delta1= max_length_orig - decimals_orig;
6512
6522
int delta2= item->max_length - item->decimals;
6513
if (fld_type == MYSQL_TYPE_DECIMAL)
6514
max_length= max(delta1, delta2) + decimals;
6516
max_length= min(max(delta1, delta2) + decimals,
6517
(fld_type == MYSQL_TYPE_FLOAT) ? FLT_DIG+6 : DBL_DIG+7);
6523
max_length= max(delta1, delta2) + decimals;
6524
if (fld_type == MYSQL_TYPE_FLOAT && max_length > FLT_DIG + 2)
6526
max_length= FLT_DIG + 6;
6527
decimals= NOT_FIXED_DEC;
6529
if (fld_type == MYSQL_TYPE_DOUBLE && max_length > DBL_DIG + 2)
6531
max_length= DBL_DIG + 7;
6532
decimals= NOT_FIXED_DEC;
6520
6536
max_length= (fld_type == MYSQL_TYPE_FLOAT) ? FLT_DIG+6 : DBL_DIG+7;