~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/item.cc

  • Committer: Monty Taylor
  • Date: 2008-10-20 08:48:34 UTC
  • mfrom: (520.1.22 drizzle)
  • Revision ID: monty@inaugust.com-20081020084834-xpb3w01vkcp55o02
Merged trunk.

Show diffs side-by-side

added added

removed removed

Lines of Context:
256
256
                     res->ptr(), res->length(), res->charset(),
257
257
                     decimal_value) & E_DEC_BAD_NUM)
258
258
  {
259
 
    push_warning_printf(current_thd, DRIZZLE_ERROR::WARN_LEVEL_WARN,
 
259
    push_warning_printf(current_session, DRIZZLE_ERROR::WARN_LEVEL_WARN,
260
260
                        ER_TRUNCATED_WRONG_VALUE,
261
261
                        ER(ER_TRUNCATED_WRONG_VALUE), "DECIMAL",
262
262
                        str_value.c_ptr());
382
382
  cmp_context= (Item_result)-1;
383
383
 
384
384
  /* Put item in free list so that we can free all items at end */
385
 
  THD *thd= current_thd;
386
 
  next= thd->free_list;
387
 
  thd->free_list= this;
 
385
  Session *session= current_session;
 
386
  next= session->free_list;
 
387
  session->free_list= this;
388
388
  /*
389
389
    Item constructor can be called during execution other then SQL_COM
390
 
    command => we should check thd->lex->current_select on zero (thd->lex
 
390
    command => we should check session->lex->current_select on zero (session->lex
391
391
    can be uninitialised)
392
392
  */
393
 
  if (thd->lex->current_select)
 
393
  if (session->lex->current_select)
394
394
  {
395
395
    enum_parsing_place place= 
396
 
      thd->lex->current_select->parsing_place;
 
396
      session->lex->current_select->parsing_place;
397
397
    if (place == SELECT_LIST ||
398
398
        place == IN_HAVING)
399
 
      thd->lex->current_select->select_n_having_items++;
 
399
      session->lex->current_select->select_n_having_items++;
400
400
  }
401
401
}
402
402
 
407
407
  Used for duplicating lists in processing queries with temporary
408
408
  tables.
409
409
*/
410
 
Item::Item(THD *thd, Item *item):
 
410
Item::Item(Session *session, Item *item):
411
411
  is_expensive_cache(-1),
412
412
  rsize(0),
413
413
  str_value(item->str_value),
424
424
  collation(item->collation),
425
425
  cmp_context(item->cmp_context)
426
426
{
427
 
  next= thd->free_list;                         // Put in free list
428
 
  thd->free_list= this;
 
427
  next= session->free_list;                             // Put in free list
 
428
  session->free_list= this;
429
429
}
430
430
 
431
431
 
446
446
 
447
447
  if (name)
448
448
  {
449
 
    THD *thd= current_thd;
 
449
    Session *session= current_session;
450
450
    str->append(STRING_WITH_LEN(" AS "));
451
 
    append_identifier(thd, str, name, (uint) strlen(name));
 
451
    append_identifier(session, str, name, (uint) strlen(name));
452
452
  }
453
453
}
454
454
 
500
500
 
501
501
  This function is designed to ease transformation of Item trees.
502
502
  Re-execution note: every such transformation is registered for
503
 
  rollback by THD::change_item_tree() and is rolled back at the end
504
 
  of execution by THD::rollback_item_tree_changes().
 
503
  rollback by Session::change_item_tree() and is rolled back at the end
 
504
  of execution by Session::rollback_item_tree_changes().
505
505
 
506
506
  Therefore:
507
507
  - this function can not be used at prepared statement prepare
508
508
  (in particular, in fix_fields!), as only permanent
509
509
  transformation of Item trees are allowed at prepare.
510
510
  - the transformer function shall allocate new Items in execution
511
 
  memory root (thd->mem_root) and not anywhere else: allocated
 
511
  memory root (session->mem_root) and not anywhere else: allocated
512
512
  items will be gone in the end of execution.
513
513
 
514
514
  If you don't need to transform an item tree, but only traverse
519
519
  @param arg            opaque argument passed to the functor
520
520
 
521
521
  @return
522
 
    Returns pointer to the new subtree root.  THD::change_item_tree()
 
522
    Returns pointer to the new subtree root.  Session::change_item_tree()
523
523
    should be called for it if transformation took place, i.e. if a
524
524
    pointer to newly allocated item is returned.
525
525
*/
548
548
  Constructor used by Item_field & Item_*_ref (see Item comment)
549
549
*/
550
550
 
551
 
Item_ident::Item_ident(THD *thd, Item_ident *item)
552
 
  :Item(thd, item),
 
551
Item_ident::Item_ident(Session *session, Item_ident *item)
 
552
  :Item(session, item),
553
553
   orig_db_name(item->orig_db_name),
554
554
   orig_table_name(item->orig_table_name), 
555
555
   orig_field_name(item->orig_field_name),
721
721
    if (orig_len != length && !is_autogenerated_name)
722
722
    {
723
723
      if (length == 0)
724
 
        push_warning_printf(current_thd, DRIZZLE_ERROR::WARN_LEVEL_WARN,
 
724
        push_warning_printf(current_session, DRIZZLE_ERROR::WARN_LEVEL_WARN,
725
725
                            ER_NAME_BECOMES_EMPTY, ER(ER_NAME_BECOMES_EMPTY),
726
726
                            str + length - orig_len);
727
727
      else
728
 
        push_warning_printf(current_thd, DRIZZLE_ERROR::WARN_LEVEL_WARN,
 
728
        push_warning_printf(current_session, DRIZZLE_ERROR::WARN_LEVEL_WARN,
729
729
                            ER_REMOVED_SPACES, ER(ER_REMOVED_SPACES),
730
730
                            str + length - orig_len);
731
731
    }
829
829
    */
830
830
    return NULL;
831
831
  }
832
 
  if (!(ptr= current_thd->strmake(cstr.ptr(), cstr.length())))
 
832
  if (!(ptr= current_session->strmake(cstr.ptr(), cstr.length())))
833
833
    return NULL;
834
834
  conv->str_value.set(ptr, cstr.length(), cstr.charset());
835
835
  /* Ensure that no one is going to change the result string */
920
920
    {
921
921
      char buff[22], *end;
922
922
      end= int64_t10_to_str(value, buff, -10);
923
 
      make_truncated_value_warning(current_thd, DRIZZLE_ERROR::WARN_LEVEL_WARN,
 
923
      make_truncated_value_warning(current_session, DRIZZLE_ERROR::WARN_LEVEL_WARN,
924
924
                                   buff, (int) (end-buff), DRIZZLE_TIMESTAMP_NONE,
925
925
                                   NULL);
926
926
      goto err;
954
954
 
955
955
const CHARSET_INFO *Item::default_charset()
956
956
{
957
 
  return current_thd->variables.collation_connection;
 
957
  return current_session->variables.collation_connection;
958
958
}
959
959
 
960
960
 
970
970
{
971
971
  int res;
972
972
  Table *table= field->table;
973
 
  THD *thd= table->in_use;
974
 
  enum_check_fields tmp= thd->count_cuted_fields;
975
 
  ulong sql_mode= thd->variables.sql_mode;
976
 
  thd->variables.sql_mode&= ~(MODE_NO_ZERO_DATE);
977
 
  thd->count_cuted_fields= CHECK_FIELD_IGNORE;
 
973
  Session *session= table->in_use;
 
974
  enum_check_fields tmp= session->count_cuted_fields;
 
975
  ulong sql_mode= session->variables.sql_mode;
 
976
  session->variables.sql_mode&= ~(MODE_NO_ZERO_DATE);
 
977
  session->count_cuted_fields= CHECK_FIELD_IGNORE;
978
978
  res= save_in_field(field, no_conversions);
979
 
  thd->count_cuted_fields= tmp;
980
 
  thd->variables.sql_mode= sql_mode;
 
979
  session->count_cuted_fields= tmp;
 
980
  session->variables.sql_mode= sql_mode;
981
981
  return res;
982
982
}
983
983
 
1007
1007
/**
1008
1008
  Move SUM items out from item tree and replace with reference.
1009
1009
 
1010
 
  @param thd                    Thread handler
 
1010
  @param session                        Thread handler
1011
1011
  @param ref_pointer_array      Pointer to array of reference fields
1012
1012
  @param fields         All fields in select
1013
1013
  @param ref                    Pointer to item
1020
1020
    All found SUM items are added FIRST in the fields list and
1021
1021
    we replace the item with a reference.
1022
1022
 
1023
 
    thd->fatal_error() may be called if we are out of memory
 
1023
    session->fatal_error() may be called if we are out of memory
1024
1024
*/
1025
1025
 
1026
 
void Item::split_sum_func2(THD *thd, Item **ref_pointer_array,
 
1026
void Item::split_sum_func2(Session *session, Item **ref_pointer_array,
1027
1027
                           List<Item> &fields, Item **ref, 
1028
1028
                           bool skip_registered)
1029
1029
{
1037
1037
        ((Item_func *) this)->functype() == Item_func::TRIG_COND_FUNC)))
1038
1038
  {
1039
1039
    /* Will split complicated items and ignore simple ones */
1040
 
    split_sum_func(thd, ref_pointer_array, fields);
 
1040
    split_sum_func(session, ref_pointer_array, fields);
1041
1041
  }
1042
1042
  else if ((type() == SUM_FUNC_ITEM || (used_tables() & ~PARAM_TABLE_BIT)) &&
1043
1043
           type() != SUBSELECT_ITEM &&
1059
1059
    Item *real_itm= real_item();
1060
1060
 
1061
1061
    ref_pointer_array[el]= real_itm;
1062
 
    if (!(item_ref= new Item_aggregate_ref(&thd->lex->current_select->context,
 
1062
    if (!(item_ref= new Item_aggregate_ref(&session->lex->current_select->context,
1063
1063
                                           ref_pointer_array + el, 0, name)))
1064
1064
      return;                                   // fatal_error is set
1065
1065
    if (type() == SUM_FUNC_ITEM)
1066
1066
      item_ref->depended_from= ((Item_sum *) this)->depended_from(); 
1067
1067
    fields.push_front(real_itm);
1068
 
    thd->change_item_tree(ref, item_ref);
 
1068
    session->change_item_tree(ref, item_ref);
1069
1069
  }
1070
1070
}
1071
1071
 
1311
1311
  @code
1312
1312
    collect(A,B,C) ::= collect(collect(A,B),C)
1313
1313
  @endcode
1314
 
  Since this function calls THD::change_item_tree() on the passed Item **
 
1314
  Since this function calls Session::change_item_tree() on the passed Item **
1315
1315
  pointers, it is necessary to pass the original Item **'s, not copies.
1316
1316
  Otherwise their values will not be properly restored (see BUG#20769).
1317
1317
  If the items are not consecutive (eg. args[2] and args[5]), use the
1344
1344
    safe_args[1]= args[item_sep];
1345
1345
  }
1346
1346
 
1347
 
  THD *thd= current_thd;
 
1347
  Session *session= current_session;
1348
1348
  bool res= false;
1349
1349
  uint32_t i;
1350
1350
 
1385
1385
      been created in prepare. In this case register the change for
1386
1386
      rollback.
1387
1387
    */
1388
 
    thd->change_item_tree(arg, conv);
 
1388
    session->change_item_tree(arg, conv);
1389
1389
    /*
1390
1390
      We do not check conv->fixed, because Item_func_conv_charset which can
1391
1391
      be return by safe_charset_converter can't be fixed at creation
1392
1392
    */
1393
 
    conv->fix_fields(thd, arg);
 
1393
    conv->fix_fields(session, arg);
1394
1394
  }
1395
1395
 
1396
1396
  return res;
1433
1433
  Item_field (this is important in prepared statements).
1434
1434
*/
1435
1435
 
1436
 
Item_field::Item_field(THD *thd __attribute__((unused)),
 
1436
Item_field::Item_field(Session *session __attribute__((unused)),
1437
1437
                       Name_resolution_context *context_arg,
1438
1438
                       Field *f)
1439
1439
  :Item_ident(context_arg, f->table->s->db.str, *f->table_name, f->field_name),
1451
1451
   field(0), result_field(0), item_equal(0), no_const_subst(0),
1452
1452
   have_privileges(0), any_privileges(0)
1453
1453
{
1454
 
  SELECT_LEX *select= current_thd->lex->current_select;
 
1454
  SELECT_LEX *select= current_session->lex->current_select;
1455
1455
  collation.set(DERIVATION_IMPLICIT);
1456
1456
  if (select && select->parsing_place != IN_HAVING)
1457
1457
      select->select_n_where_fields++;
1461
1461
  Constructor need to process subselect with temporary tables (see Item)
1462
1462
*/
1463
1463
 
1464
 
Item_field::Item_field(THD *thd, Item_field *item)
1465
 
  :Item_ident(thd, item),
 
1464
Item_field::Item_field(Session *session, Item_field *item)
 
1465
  :Item_ident(session, item),
1466
1466
   field(item->field),
1467
1467
   result_field(item->result_field),
1468
1468
   item_equal(item->item_equal),
1532
1532
void Item_ident::print(String *str,
1533
1533
                       enum_query_type query_type __attribute__((unused)))
1534
1534
{
1535
 
  THD *thd= current_thd;
 
1535
  Session *session= current_session;
1536
1536
  char d_name_buff[MAX_ALIAS_NAME], t_name_buff[MAX_ALIAS_NAME];
1537
1537
  const char *d_name= db_name, *t_name= table_name;
1538
1538
  if (lower_case_table_names== 1 ||
1556
1556
  {
1557
1557
    const char *nm= (field_name && field_name[0]) ?
1558
1558
                      field_name : name ? name : "tmp_field";
1559
 
    append_identifier(thd, str, nm, (uint) strlen(nm));
 
1559
    append_identifier(session, str, nm, (uint) strlen(nm));
1560
1560
    return;
1561
1561
  }
1562
1562
  if (db_name && db_name[0] && !alias_name_used)
1563
1563
  {
1564
1564
    {
1565
 
      append_identifier(thd, str, d_name, (uint)strlen(d_name));
 
1565
      append_identifier(session, str, d_name, (uint)strlen(d_name));
1566
1566
      str->append('.');
1567
1567
    }
1568
 
    append_identifier(thd, str, t_name, (uint)strlen(t_name));
 
1568
    append_identifier(session, str, t_name, (uint)strlen(t_name));
1569
1569
    str->append('.');
1570
 
    append_identifier(thd, str, field_name, (uint)strlen(field_name));
 
1570
    append_identifier(session, str, field_name, (uint)strlen(field_name));
1571
1571
  }
1572
1572
  else
1573
1573
  {
1574
1574
    if (table_name[0])
1575
1575
    {
1576
 
      append_identifier(thd, str, t_name, (uint) strlen(t_name));
 
1576
      append_identifier(session, str, t_name, (uint) strlen(t_name));
1577
1577
      str->append('.');
1578
 
      append_identifier(thd, str, field_name, (uint) strlen(field_name));
 
1578
      append_identifier(session, str, field_name, (uint) strlen(field_name));
1579
1579
    }
1580
1580
    else
1581
 
      append_identifier(thd, str, field_name, (uint) strlen(field_name));
 
1581
      append_identifier(session, str, field_name, (uint) strlen(field_name));
1582
1582
  }
1583
1583
}
1584
1584
 
1760
1760
}
1761
1761
 
1762
1762
 
1763
 
Item *Item_field::get_tmp_table_item(THD *thd)
 
1763
Item *Item_field::get_tmp_table_item(Session *session)
1764
1764
{
1765
 
  Item_field *new_item= new Item_field(thd, this);
 
1765
  Item_field *new_item= new Item_field(session, this);
1766
1766
  if (new_item)
1767
1767
    new_item->field= new_item->result_field;
1768
1768
  return new_item;
2005
2005
  }
2006
2006
  else
2007
2007
  {
2008
 
    THD *thd= current_thd;
 
2008
    Session *session= current_session;
2009
2009
    LEX_STRING utf8_lex_str;
2010
2010
 
2011
 
    thd->convert_string(&utf8_lex_str,
 
2011
    session->convert_string(&utf8_lex_str,
2012
2012
                        system_charset_info,
2013
2013
                        str_value.c_ptr_safe(),
2014
2014
                        str_value.length(),
2042
2042
      We can use str_value.ptr() here as Item_string is gurantee to put an
2043
2043
      end \0 here.
2044
2044
    */
2045
 
    push_warning_printf(current_thd, DRIZZLE_ERROR::WARN_LEVEL_WARN,
 
2045
    push_warning_printf(current_session, DRIZZLE_ERROR::WARN_LEVEL_WARN,
2046
2046
                        ER_TRUNCATED_WRONG_VALUE,
2047
2047
                        ER(ER_TRUNCATED_WRONG_VALUE), "DOUBLE",
2048
2048
                        str_value.ptr());
2072
2072
  if (err > 0 ||
2073
2073
      (end != org_end && !check_if_only_end_space(cs, end, org_end)))
2074
2074
  {
2075
 
    push_warning_printf(current_thd, DRIZZLE_ERROR::WARN_LEVEL_WARN,
 
2075
    push_warning_printf(current_session, DRIZZLE_ERROR::WARN_LEVEL_WARN,
2076
2076
                        ER_TRUNCATED_WRONG_VALUE,
2077
2077
                        ER(ER_TRUNCATED_WRONG_VALUE), "INTEGER",
2078
2078
                        str_value.ptr());
2256
2256
  {
2257
2257
    char buff[MAX_DATE_STRING_REP_LENGTH];
2258
2258
    uint32_t length= my_TIME_to_str(&value.time, buff);
2259
 
    make_truncated_value_warning(current_thd, DRIZZLE_ERROR::WARN_LEVEL_WARN,
 
2259
    make_truncated_value_warning(current_session, DRIZZLE_ERROR::WARN_LEVEL_WARN,
2260
2260
                                 buff, length, time_type, 0);
2261
2261
    set_zero_time(&value.time, DRIZZLE_TIMESTAMP_ERROR);
2262
2262
  }
2311
2311
/**
2312
2312
  Set parameter value from user variable value.
2313
2313
 
2314
 
  @param thd   Current thread
 
2314
  @param session   Current thread
2315
2315
  @param entry User variable structure (NULL means use NULL value)
2316
2316
 
2317
2317
  @retval
2320
2320
    1 Out of memory
2321
2321
*/
2322
2322
 
2323
 
bool Item_param::set_from_user_var(THD *thd, const user_var_entry *entry)
 
2323
bool Item_param::set_from_user_var(Session *session, const user_var_entry *entry)
2324
2324
{
2325
2325
  if (entry && entry->value)
2326
2326
  {
2345
2345
    case STRING_RESULT:
2346
2346
    {
2347
2347
      const CHARSET_INFO * const fromcs= entry->collation.collation;
2348
 
      const CHARSET_INFO * const tocs= thd->variables.collation_connection;
 
2348
      const CHARSET_INFO * const tocs= session->variables.collation_connection;
2349
2349
      uint32_t dummy_offset;
2350
2350
 
2351
2351
      value.cs_info.character_set_of_placeholder= 
2678
2678
  connection.
2679
2679
*/
2680
2680
 
2681
 
bool Item_param::convert_str_value(THD *thd)
 
2681
bool Item_param::convert_str_value(Session *session)
2682
2682
{
2683
2683
  bool rc= false;
2684
2684
  if (state == STRING_VALUE || state == LONG_DATA_VALUE)
2692
2692
    if (value.cs_info.final_character_set_of_str_value !=
2693
2693
        value.cs_info.character_set_of_placeholder)
2694
2694
    {
2695
 
      rc= thd->convert_string(&str_value,
 
2695
      rc= session->convert_string(&str_value,
2696
2696
                              value.cs_info.character_set_of_placeholder,
2697
2697
                              value.cs_info.final_character_set_of_str_value);
2698
2698
    }
2838
2838
*/
2839
2839
 
2840
2840
/* ARGSUSED */
2841
 
bool Item::fix_fields(THD *thd __attribute__((unused)),
 
2841
bool Item::fix_fields(Session *session __attribute__((unused)),
2842
2842
                      Item **ref __attribute__((unused)))
2843
2843
{
2844
2844
 
2903
2903
  Mark item and SELECT_LEXs as dependent if item was resolved in
2904
2904
  outer SELECT.
2905
2905
 
2906
 
  @param thd             thread handler
 
2906
  @param session             thread handler
2907
2907
  @param last            select from which current item depend
2908
2908
  @param current         current select
2909
2909
  @param resolved_item   item which was resolved in outer SELECT(for warning)
2911
2911
                         substitution)
2912
2912
*/
2913
2913
 
2914
 
static void mark_as_dependent(THD *thd, SELECT_LEX *last, SELECT_LEX *current,
 
2914
static void mark_as_dependent(Session *session, SELECT_LEX *last, SELECT_LEX *current,
2915
2915
                              Item_ident *resolved_item,
2916
2916
                              Item_ident *mark_item)
2917
2917
{
2923
2923
  if (mark_item)
2924
2924
    mark_item->depended_from= last;
2925
2925
  current->mark_as_dependent(last);
2926
 
  if (thd->lex->describe & DESCRIBE_EXTENDED)
 
2926
  if (session->lex->describe & DESCRIBE_EXTENDED)
2927
2927
  {
2928
2928
    char warn_buff[DRIZZLE_ERRMSG_SIZE];
2929
2929
    sprintf(warn_buff, ER(ER_WARN_FIELD_RESOLVED),
2931
2931
            table_name, (table_name [0] ? "." : ""),
2932
2932
            resolved_item->field_name,
2933
2933
            current->select_number, last->select_number);
2934
 
    push_warning(thd, DRIZZLE_ERROR::WARN_LEVEL_NOTE,
 
2934
    push_warning(session, DRIZZLE_ERROR::WARN_LEVEL_NOTE,
2935
2935
                 ER_WARN_FIELD_RESOLVED, warn_buff);
2936
2936
  }
2937
2937
}
2941
2941
  Mark range of selects and resolved identifier (field/reference)
2942
2942
  item as dependent.
2943
2943
 
2944
 
  @param thd             thread handler
 
2944
  @param session             thread handler
2945
2945
  @param last_select     select where resolved_item was resolved
2946
2946
  @param current_sel     current select (select where resolved_item was placed)
2947
2947
  @param found_field     field which was found during resolving
2957
2957
    resolved identifier.
2958
2958
*/
2959
2959
 
2960
 
void mark_select_range_as_dependent(THD *thd,
 
2960
void mark_select_range_as_dependent(Session *session,
2961
2961
                                    SELECT_LEX *last_select,
2962
2962
                                    SELECT_LEX *current_sel,
2963
2963
                                    Field *found_field, Item *found_item,
2995
2995
      prev_subselect_item->used_tables_cache|=
2996
2996
        found_field->table->map;
2997
2997
    prev_subselect_item->const_item_cache= 0;
2998
 
    mark_as_dependent(thd, last_select, current_sel, resolved_item,
 
2998
    mark_as_dependent(session, last_select, current_sel, resolved_item,
2999
2999
                      dependent);
3000
3000
  }
3001
3001
}
3094
3094
          is ambiguous.
3095
3095
        */
3096
3096
        my_error(ER_NON_UNIQ_ERROR, MYF(0),
3097
 
                 find_item->full_name(), current_thd->where);
 
3097
                 find_item->full_name(), current_session->where);
3098
3098
        return NULL;
3099
3099
      }
3100
3100
    }
3120
3120
  derived SELECT column. This extension is allowed only if the
3121
3121
  MODE_ONLY_FULL_GROUP_BY sql mode isn't enabled.
3122
3122
 
3123
 
  @param thd     current thread
 
3123
  @param session     current thread
3124
3124
  @param ref     column reference being resolved
3125
3125
  @param select  the select that ref is resolved against
3126
3126
 
3144
3144
*/
3145
3145
 
3146
3146
static Item**
3147
 
resolve_ref_in_select_and_group(THD *thd, Item_ident *ref, SELECT_LEX *select)
 
3147
resolve_ref_in_select_and_group(Session *session, Item_ident *ref, SELECT_LEX *select)
3148
3148
{
3149
3149
  Item **group_by_ref= NULL;
3150
3150
  Item **select_ref= NULL;
3174
3174
        !((*group_by_ref)->eq(*select_ref, 0)))
3175
3175
    {
3176
3176
      ambiguous_fields= true;
3177
 
      push_warning_printf(thd, DRIZZLE_ERROR::WARN_LEVEL_WARN, ER_NON_UNIQ_ERROR,
 
3177
      push_warning_printf(session, DRIZZLE_ERROR::WARN_LEVEL_WARN, ER_NON_UNIQ_ERROR,
3178
3178
                          ER(ER_NON_UNIQ_ERROR), ref->full_name(),
3179
 
                          current_thd->where);
 
3179
                          current_session->where);
3180
3180
 
3181
3181
    }
3182
3182
  }
3217
3217
  current select as dependent. The found reference of field should be
3218
3218
  provided in 'from_field'.
3219
3219
 
3220
 
  @param[in] thd             current thread
 
3220
  @param[in] session             current thread
3221
3221
  @param[in,out] from_field  found field reference or (Field*)not_found_field
3222
3222
  @param[in,out] reference   view column if this item was resolved to a
3223
3223
    view column
3245
3245
*/
3246
3246
 
3247
3247
int
3248
 
Item_field::fix_outer_field(THD *thd, Field **from_field, Item **reference)
 
3248
Item_field::fix_outer_field(Session *session, Field **from_field, Item **reference)
3249
3249
{
3250
3250
  enum_parsing_place place= NO_MATTER;
3251
3251
  bool field_found= (*from_field != not_found_field);
3262
3262
  */
3263
3263
  Name_resolution_context *last_checked_context= context;
3264
3264
  Item **ref= (Item **) not_found_item;
3265
 
  SELECT_LEX *current_sel= (SELECT_LEX *) thd->lex->current_select;
 
3265
  SELECT_LEX *current_sel= (SELECT_LEX *) session->lex->current_select;
3266
3266
  Name_resolution_context *outer_context= 0;
3267
3267
  SELECT_LEX *select= 0;
3268
3268
  /* Currently derived tables cannot be correlated */
3292
3292
      the found view field into '*reference', in other words, it
3293
3293
      substitutes this Item_field with the found expression.
3294
3294
    */
3295
 
    if (field_found || (*from_field= find_field_in_tables(thd, this,
 
3295
    if (field_found || (*from_field= find_field_in_tables(session, this,
3296
3296
                                          outer_context->
3297
3297
                                            first_name_resolution_table,
3298
3298
                                          outer_context->
3326
3326
            ;
3327
3327
            if (!(rf= new Item_outer_ref(context, this)))
3328
3328
              return -1;
3329
 
            thd->change_item_tree(reference, rf);
 
3329
            session->change_item_tree(reference, rf);
3330
3330
            select->inner_refs_list.push_back(rf);
3331
 
            rf->in_sum_func= thd->lex->in_sum_func;
 
3331
            rf->in_sum_func= session->lex->in_sum_func;
3332
3332
          }
3333
3333
          /*
3334
3334
            A reference is resolved to a nest level that's outer or the same as
3335
3335
            the nest level of the enclosing set function : adjust the value of
3336
3336
            max_arg_level for the function if it's needed.
3337
3337
          */
3338
 
          if (thd->lex->in_sum_func &&
3339
 
              thd->lex->in_sum_func->nest_level >= select->nest_level)
 
3338
          if (session->lex->in_sum_func &&
 
3339
              session->lex->in_sum_func->nest_level >= select->nest_level)
3340
3340
          {
3341
3341
            Item::Type ref_type= (*reference)->type();
3342
 
            set_if_bigger(thd->lex->in_sum_func->max_arg_level,
 
3342
            set_if_bigger(session->lex->in_sum_func->max_arg_level,
3343
3343
                          select->nest_level);
3344
3344
            set_field(*from_field);
3345
3345
            fixed= 1;
3346
 
            mark_as_dependent(thd, last_checked_context->select_lex,
 
3346
            mark_as_dependent(session, last_checked_context->select_lex,
3347
3347
                              context->select_lex, this,
3348
3348
                              ((ref_type == REF_ITEM ||
3349
3349
                                ref_type == FIELD_ITEM) ?
3358
3358
            (*reference)->used_tables();
3359
3359
          prev_subselect_item->const_item_cache&=
3360
3360
            (*reference)->const_item();
3361
 
          mark_as_dependent(thd, last_checked_context->select_lex,
 
3361
          mark_as_dependent(session, last_checked_context->select_lex,
3362
3362
                            context->select_lex, this,
3363
3363
                            ((ref_type == REF_ITEM || ref_type == FIELD_ITEM) ?
3364
3364
                             (Item_ident*) (*reference) :
3378
3378
    /* Search in SELECT and GROUP lists of the outer select. */
3379
3379
    if (place != IN_WHERE && place != IN_ON)
3380
3380
    {
3381
 
      if (!(ref= resolve_ref_in_select_and_group(thd, this, select)))
 
3381
      if (!(ref= resolve_ref_in_select_and_group(session, this, select)))
3382
3382
        return -1; /* Some error occurred (e.g. ambiguous names). */
3383
3383
      if (ref != not_found_item)
3384
3384
      {
3406
3406
    if (upward_lookup)
3407
3407
    {
3408
3408
      // We can't say exactly what absent table or field
3409
 
      my_error(ER_BAD_FIELD_ERROR, MYF(0), full_name(), thd->where);
 
3409
      my_error(ER_BAD_FIELD_ERROR, MYF(0), full_name(), session->where);
3410
3410
    }
3411
3411
    else
3412
3412
    {
3413
3413
      /* Call find_field_in_tables only to report the error */
3414
 
      find_field_in_tables(thd, this,
 
3414
      find_field_in_tables(session, this,
3415
3415
                           context->first_name_resolution_table,
3416
3416
                           context->last_name_resolution_table,
3417
3417
                           reference, REPORT_ALL_ERRORS,
3450
3450
    if (place != IN_HAVING && select->group_list.elements)
3451
3451
    {
3452
3452
      outer_context->select_lex->inner_refs_list.push_back((Item_outer_ref*)rf);
3453
 
      ((Item_outer_ref*)rf)->in_sum_func= thd->lex->in_sum_func;
 
3453
      ((Item_outer_ref*)rf)->in_sum_func= session->lex->in_sum_func;
3454
3454
    }
3455
 
    thd->change_item_tree(reference, rf);
 
3455
    session->change_item_tree(reference, rf);
3456
3456
    /*
3457
3457
      rf is Item_ref => never substitute other items (in this case)
3458
3458
      during fix_fields() => we can use rf after fix_fields()
3459
3459
    */
3460
3460
    assert(!rf->fixed);                // Assured by Item_ref()
3461
 
    if (rf->fix_fields(thd, reference) || rf->check_cols(1))
 
3461
    if (rf->fix_fields(session, reference) || rf->check_cols(1))
3462
3462
      return -1;
3463
3463
 
3464
 
    mark_as_dependent(thd, last_checked_context->select_lex,
 
3464
    mark_as_dependent(session, last_checked_context->select_lex,
3465
3465
                      context->select_lex, this,
3466
3466
                      rf);
3467
3467
    return 0;
3468
3468
  }
3469
3469
  else
3470
3470
  {
3471
 
    mark_as_dependent(thd, last_checked_context->select_lex,
 
3471
    mark_as_dependent(session, last_checked_context->select_lex,
3472
3472
                      context->select_lex,
3473
3473
                      this, (Item_ident*)*reference);
3474
3474
    if (last_checked_context->select_lex->having_fix_field)
3479
3479
                       (char*) cached_table->alias, (char*) field_name);
3480
3480
      if (!rf)
3481
3481
        return -1;
3482
 
      thd->change_item_tree(reference, rf);
 
3482
      session->change_item_tree(reference, rf);
3483
3483
      /*
3484
3484
        rf is Item_ref => never substitute other items (in this case)
3485
3485
        during fix_fields() => we can use rf after fix_fields()
3486
3486
      */
3487
3487
      assert(!rf->fixed);                // Assured by Item_ref()
3488
 
      if (rf->fix_fields(thd, reference) || rf->check_cols(1))
 
3488
      if (rf->fix_fields(session, reference) || rf->check_cols(1))
3489
3489
        return -1;
3490
3490
      return 0;
3491
3491
    }
3529
3529
    Notice that compared to Item_ref::fix_fields, here we first search the FROM
3530
3530
    clause, and then we search the SELECT and GROUP BY clauses.
3531
3531
 
3532
 
  @param[in]     thd        current thread
 
3532
  @param[in]     session        current thread
3533
3533
  @param[in,out] reference  view column if this item was resolved to a
3534
3534
    view column
3535
3535
 
3539
3539
    false on success
3540
3540
*/
3541
3541
 
3542
 
bool Item_field::fix_fields(THD *thd, Item **reference)
 
3542
bool Item_field::fix_fields(Session *session, Item **reference)
3543
3543
{
3544
3544
  assert(fixed == 0);
3545
3545
  Field *from_field= (Field *)not_found_field;
3552
3552
      expression to 'reference', i.e. it substitute that expression instead
3553
3553
      of this Item_field
3554
3554
    */
3555
 
    if ((from_field= find_field_in_tables(thd, this,
 
3555
    if ((from_field= find_field_in_tables(session, this,
3556
3556
                                          context->first_name_resolution_table,
3557
3557
                                          context->last_name_resolution_table,
3558
3558
                                          reference,
3559
 
                                          thd->lex->use_only_table_context ?
 
3559
                                          session->lex->use_only_table_context ?
3560
3560
                                            REPORT_ALL_ERRORS : 
3561
3561
                                            IGNORE_EXCEPT_NON_UNIQUE,
3562
3562
                                          !any_privileges,
3565
3565
    {
3566
3566
      int ret;
3567
3567
      /* Look up in current select's item_list to find aliased fields */
3568
 
      if (thd->lex->current_select->is_item_list_lookup)
 
3568
      if (session->lex->current_select->is_item_list_lookup)
3569
3569
      {
3570
3570
        uint32_t counter;
3571
3571
        enum_resolution_type resolution;
3572
 
        Item** res= find_item_in_list(this, thd->lex->current_select->item_list,
 
3572
        Item** res= find_item_in_list(this, session->lex->current_select->item_list,
3573
3573
                                      &counter, REPORT_EXCEPT_NOT_FOUND,
3574
3574
                                      &resolution);
3575
3575
        if (!res)
3593
3593
            {
3594
3594
              /* The column to which we link isn't valid. */
3595
3595
              my_error(ER_BAD_FIELD_ERROR, MYF(0), (*res)->name, 
3596
 
                       current_thd->where);
 
3596
                       current_session->where);
3597
3597
              return(1);
3598
3598
            }
3599
3599
 
3610
3610
            Item_ref *rf= new Item_ref(context, db_name,table_name,field_name);
3611
3611
            if (!rf)
3612
3612
              return 1;
3613
 
            thd->change_item_tree(reference, rf);
 
3613
            session->change_item_tree(reference, rf);
3614
3614
            /*
3615
3615
              Because Item_ref never substitutes itself with other items 
3616
3616
              in Item_ref::fix_fields(), we can safely use the original 
3617
3617
              pointer to it even after fix_fields()
3618
3618
             */
3619
 
            return rf->fix_fields(thd, reference) ||  rf->check_cols(1);
 
3619
            return rf->fix_fields(session, reference) ||  rf->check_cols(1);
3620
3620
          }
3621
3621
        }
3622
3622
      }
3623
 
      if ((ret= fix_outer_field(thd, &from_field, reference)) < 0)
 
3623
      if ((ret= fix_outer_field(session, &from_field, reference)) < 0)
3624
3624
        goto error;
3625
3625
      outer_fixed= true;
3626
3626
      if (!ret)
3634
3634
        cached_table->select_lex != context->select_lex)
3635
3635
    {
3636
3636
      int ret;
3637
 
      if ((ret= fix_outer_field(thd, &from_field, reference)) < 0)
 
3637
      if ((ret= fix_outer_field(session, &from_field, reference)) < 0)
3638
3638
        goto error;
3639
3639
      outer_fixed= 1;
3640
3640
      if (!ret)
3657
3657
      return false;
3658
3658
 
3659
3659
    set_field(from_field);
3660
 
    if (thd->lex->in_sum_func &&
3661
 
        thd->lex->in_sum_func->nest_level == 
3662
 
        thd->lex->current_select->nest_level)
3663
 
      set_if_bigger(thd->lex->in_sum_func->max_arg_level,
3664
 
                    thd->lex->current_select->nest_level);
 
3660
    if (session->lex->in_sum_func &&
 
3661
        session->lex->in_sum_func->nest_level == 
 
3662
        session->lex->current_select->nest_level)
 
3663
      set_if_bigger(session->lex->in_sum_func->max_arg_level,
 
3664
                    session->lex->current_select->nest_level);
3665
3665
  }
3666
 
  else if (thd->mark_used_columns != MARK_COLUMNS_NONE)
 
3666
  else if (session->mark_used_columns != MARK_COLUMNS_NONE)
3667
3667
  {
3668
3668
    Table *table= field->table;
3669
3669
    MY_BITMAP *current_bitmap, *other_bitmap;
3670
 
    if (thd->mark_used_columns == MARK_COLUMNS_READ)
 
3670
    if (session->mark_used_columns == MARK_COLUMNS_READ)
3671
3671
    {
3672
3672
      current_bitmap= table->read_set;
3673
3673
      other_bitmap=   table->write_set;
3694
3694
  return false;
3695
3695
 
3696
3696
error:
3697
 
  context->process_error(thd);
 
3697
  context->process_error(session);
3698
3698
  return true;
3699
3699
}
3700
3700
 
3982
3982
                                       str->length(), &well_formed_error);
3983
3983
  if (wlen < str->length())
3984
3984
  {
3985
 
    THD *thd= current_thd;
 
3985
    Session *session= current_session;
3986
3986
    char hexbuf[7];
3987
3987
    enum DRIZZLE_ERROR::enum_warning_level level;
3988
3988
    uint32_t diff= str->length() - wlen;
3999
3999
      null_value= 1;
4000
4000
      str= 0;
4001
4001
    }
4002
 
    push_warning_printf(thd, level, ER_INVALID_CHARACTER_STRING,
 
4002
    push_warning_printf(session, level, ER_INVALID_CHARACTER_STRING,
4003
4003
                        ER(ER_INVALID_CHARACTER_STRING), cs->csname, hexbuf);
4004
4004
  }
4005
4005
  return str;
4732
4732
    need to set no_errors to prevent warnings about type conversion
4733
4733
    popping up.
4734
4734
  */
4735
 
  THD *thd= field->table->in_use;
 
4735
  Session *session= field->table->in_use;
4736
4736
  int no_errors;
4737
4737
 
4738
 
  no_errors= thd->no_errors;
4739
 
  thd->no_errors= 1;
 
4738
  no_errors= session->no_errors;
 
4739
  session->no_errors= 1;
4740
4740
  Item::update_null_value();
4741
 
  thd->no_errors= no_errors;
 
4741
  session->no_errors= no_errors;
4742
4742
}
4743
4743
 
4744
4744
 
4866
4866
    Item_field::fix_fields, here we first search the SELECT and GROUP BY
4867
4867
    clauses, and then we search the FROM clause.
4868
4868
 
4869
 
  @param[in]     thd        current thread
 
4869
  @param[in]     session        current thread
4870
4870
  @param[in,out] reference  view column if this item was resolved to a
4871
4871
    view column
4872
4872
 
4882
4882
    false on success
4883
4883
*/
4884
4884
 
4885
 
bool Item_ref::fix_fields(THD *thd, Item **reference)
 
4885
bool Item_ref::fix_fields(Session *session, Item **reference)
4886
4886
{
4887
4887
  enum_parsing_place place= NO_MATTER;
4888
4888
  assert(fixed == 0);
4889
 
  SELECT_LEX *current_sel= thd->lex->current_select;
 
4889
  SELECT_LEX *current_sel= session->lex->current_select;
4890
4890
 
4891
4891
  if (!ref || ref == not_found_item)
4892
4892
  {
4893
 
    if (!(ref= resolve_ref_in_select_and_group(thd, this,
 
4893
    if (!(ref= resolve_ref_in_select_and_group(session, this,
4894
4894
                                               context->select_lex)))
4895
4895
      goto error;             /* Some error occurred (e.g. ambiguous names). */
4896
4896
 
4905
4905
      {
4906
4906
        /* The current reference cannot be resolved in this query. */
4907
4907
        my_error(ER_BAD_FIELD_ERROR,MYF(0),
4908
 
                 this->full_name(), current_thd->where);
 
4908
                 this->full_name(), current_session->where);
4909
4909
        goto error;
4910
4910
      }
4911
4911
 
4930
4930
        /* Search in the SELECT and GROUP lists of the outer select. */
4931
4931
        if (outer_context->resolve_in_select_list)
4932
4932
        {
4933
 
          if (!(ref= resolve_ref_in_select_and_group(thd, this, select)))
 
4933
          if (!(ref= resolve_ref_in_select_and_group(session, this, select)))
4934
4934
            goto error; /* Some error occurred (e.g. ambiguous names). */
4935
4935
          if (ref != not_found_item)
4936
4936
          {
4967
4967
            field expression to 'reference', i.e. it substitute that
4968
4968
            expression instead of this Item_ref
4969
4969
          */
4970
 
          from_field= find_field_in_tables(thd, this,
 
4970
          from_field= find_field_in_tables(session, this,
4971
4971
                                           outer_context->
4972
4972
                                             first_name_resolution_table,
4973
4973
                                           outer_context->
4985
4985
            prev_subselect_item->const_item_cache&=
4986
4986
              (*reference)->const_item();
4987
4987
            assert((*reference)->type() == REF_ITEM);
4988
 
            mark_as_dependent(thd, last_checked_context->select_lex,
 
4988
            mark_as_dependent(session, last_checked_context->select_lex,
4989
4989
                              context->select_lex, this,
4990
4990
                              ((refer_type == REF_ITEM ||
4991
4991
                                refer_type == FIELD_ITEM) ?
5038
5038
        Item_field* fld;
5039
5039
        if (!(fld= new Item_field(from_field)))
5040
5040
          goto error;
5041
 
        thd->change_item_tree(reference, fld);
5042
 
        mark_as_dependent(thd, last_checked_context->select_lex,
5043
 
                          thd->lex->current_select, this, fld);
 
5041
        session->change_item_tree(reference, fld);
 
5042
        mark_as_dependent(session, last_checked_context->select_lex,
 
5043
                          session->lex->current_select, this, fld);
5044
5044
        /*
5045
5045
          A reference is resolved to a nest level that's outer or the same as
5046
5046
          the nest level of the enclosing set function : adjust the value of
5047
5047
          max_arg_level for the function if it's needed.
5048
5048
        */
5049
 
        if (thd->lex->in_sum_func &&
5050
 
            thd->lex->in_sum_func->nest_level >= 
 
5049
        if (session->lex->in_sum_func &&
 
5050
            session->lex->in_sum_func->nest_level >= 
5051
5051
            last_checked_context->select_lex->nest_level)
5052
 
          set_if_bigger(thd->lex->in_sum_func->max_arg_level,
 
5052
          set_if_bigger(session->lex->in_sum_func->max_arg_level,
5053
5053
                        last_checked_context->select_lex->nest_level);
5054
5054
        return false;
5055
5055
      }
5057
5057
      {
5058
5058
        /* The item was not a table field and not a reference */
5059
5059
        my_error(ER_BAD_FIELD_ERROR, MYF(0),
5060
 
                 this->full_name(), current_thd->where);
 
5060
                 this->full_name(), current_session->where);
5061
5061
        goto error;
5062
5062
      }
5063
5063
      /* Should be checked in resolve_ref_in_select_and_group(). */
5064
5064
      assert(*ref && (*ref)->fixed);
5065
 
      mark_as_dependent(thd, last_checked_context->select_lex,
 
5065
      mark_as_dependent(session, last_checked_context->select_lex,
5066
5066
                        context->select_lex, this, this);
5067
5067
      /*
5068
5068
        A reference is resolved to a nest level that's outer or the same as
5069
5069
        the nest level of the enclosing set function : adjust the value of
5070
5070
        max_arg_level for the function if it's needed.
5071
5071
      */
5072
 
      if (thd->lex->in_sum_func &&
5073
 
          thd->lex->in_sum_func->nest_level >= 
 
5072
      if (session->lex->in_sum_func &&
 
5073
          session->lex->in_sum_func->nest_level >= 
5074
5074
          last_checked_context->select_lex->nest_level)
5075
 
        set_if_bigger(thd->lex->in_sum_func->max_arg_level,
 
5075
        set_if_bigger(session->lex->in_sum_func->max_arg_level,
5076
5076
                      last_checked_context->select_lex->nest_level);
5077
5077
    }
5078
5078
  }
5105
5105
  return false;
5106
5106
 
5107
5107
error:
5108
 
  context->process_error(thd);
 
5108
  context->process_error(session);
5109
5109
  return true;
5110
5110
}
5111
5111
 
5147
5147
    if ((*ref)->type() != Item::CACHE_ITEM && ref_type() != VIEW_REF &&
5148
5148
        !table_name && name && alias_name_used)
5149
5149
    {
5150
 
      THD *thd= current_thd;
5151
 
      append_identifier(thd, str, name, (uint) strlen(name));
 
5150
      Session *session= current_session;
 
5151
      append_identifier(session, str, name, (uint) strlen(name));
5152
5152
    }
5153
5153
    else
5154
5154
      (*ref)->print(str, query_type);
5329
5329
}
5330
5330
 
5331
5331
 
5332
 
Item *Item_ref::get_tmp_table_item(THD *thd)
 
5332
Item *Item_ref::get_tmp_table_item(Session *session)
5333
5333
{
5334
5334
  if (!result_field)
5335
 
    return (*ref)->get_tmp_table_item(thd);
 
5335
    return (*ref)->get_tmp_table_item(session);
5336
5336
 
5337
5337
  Item_field *item= new Item_field(result_field);
5338
5338
  if (item)
5410
5410
/**
5411
5411
  Prepare referenced field then call usual Item_direct_ref::fix_fields .
5412
5412
 
5413
 
  @param thd         thread handler
 
5413
  @param session         thread handler
5414
5414
  @param reference   reference on reference where this item stored
5415
5415
 
5416
5416
  @retval
5419
5419
    true    Error
5420
5420
*/
5421
5421
 
5422
 
bool Item_direct_view_ref::fix_fields(THD *thd, Item **reference)
 
5422
bool Item_direct_view_ref::fix_fields(Session *session, Item **reference)
5423
5423
{
5424
5424
  /* view fild reference must be defined */
5425
5425
  assert(*ref);
5426
5426
  /* (*ref)->check_cols() will be made in Item_direct_ref::fix_fields */
5427
5427
  if (!(*ref)->fixed &&
5428
 
      ((*ref)->fix_fields(thd, ref)))
 
5428
      ((*ref)->fix_fields(session, ref)))
5429
5429
    return true;
5430
 
  return Item_direct_ref::fix_fields(thd, reference);
 
5430
  return Item_direct_ref::fix_fields(session, reference);
5431
5431
}
5432
5432
 
5433
5433
/*
5435
5435
 
5436
5436
  SYNOPSIS
5437
5437
    Item_outer_ref::fix_fields()
5438
 
    thd         thread handler
 
5438
    session         thread handler
5439
5439
    reference   reference on reference where this item stored
5440
5440
 
5441
5441
  RETURN
5443
5443
    true    Error
5444
5444
*/
5445
5445
 
5446
 
bool Item_outer_ref::fix_fields(THD *thd, Item **reference)
 
5446
bool Item_outer_ref::fix_fields(Session *session, Item **reference)
5447
5447
{
5448
5448
  bool err;
5449
5449
  /* outer_ref->check_cols() will be made in Item_direct_ref::fix_fields */
5450
 
  if ((*ref) && !(*ref)->fixed && ((*ref)->fix_fields(thd, reference)))
 
5450
  if ((*ref) && !(*ref)->fixed && ((*ref)->fix_fields(session, reference)))
5451
5451
    return true;
5452
 
  err= Item_direct_ref::fix_fields(thd, reference);
 
5452
  err= Item_direct_ref::fix_fields(session, reference);
5453
5453
  if (!outer_ref)
5454
5454
    outer_ref= *ref;
5455
5455
  if ((*ref)->type() == Item::FIELD_ITEM)
5515
5515
}
5516
5516
 
5517
5517
 
5518
 
bool Item_default_value::fix_fields(THD *thd,
 
5518
bool Item_default_value::fix_fields(Session *session,
5519
5519
                                    Item **items __attribute__((unused)))
5520
5520
{
5521
5521
  Item *real_arg;
5528
5528
    fixed= 1;
5529
5529
    return false;
5530
5530
  }
5531
 
  if (!arg->fixed && arg->fix_fields(thd, &arg))
 
5531
  if (!arg->fixed && arg->fix_fields(session, &arg))
5532
5532
    goto error;
5533
5533
 
5534
5534
 
5555
5555
  return false;
5556
5556
 
5557
5557
error:
5558
 
  context->process_error(thd);
 
5558
  context->process_error(session);
5559
5559
  return true;
5560
5560
}
5561
5561
 
5614
5614
    return 0;
5615
5615
 
5616
5616
  /*
5617
 
    THD::change_item_tree() should be called only if the tree was
 
5617
    Session::change_item_tree() should be called only if the tree was
5618
5618
    really transformed, i.e. when a new item has been created.
5619
5619
    Otherwise we'll be allocating a lot of unnecessary memory for
5620
5620
    change records at each execution.
5621
5621
  */
5622
5622
  if (arg != new_item)
5623
 
    current_thd->change_item_tree(&arg, new_item);
 
5623
    current_session->change_item_tree(&arg, new_item);
5624
5624
  return (this->*transformer)(args);
5625
5625
}
5626
5626
 
5632
5632
}
5633
5633
 
5634
5634
 
5635
 
bool Item_insert_value::fix_fields(THD *thd,
 
5635
bool Item_insert_value::fix_fields(Session *session,
5636
5636
                                   Item **items __attribute__((unused)))
5637
5637
{
5638
5638
  assert(fixed == 0);
5642
5642
    bool res;
5643
5643
    TableList *orig_next_table= context->last_name_resolution_table;
5644
5644
    context->last_name_resolution_table= context->first_name_resolution_table;
5645
 
    res= arg->fix_fields(thd, &arg);
 
5645
    res= arg->fix_fields(session, &arg);
5646
5646
    context->last_name_resolution_table= orig_next_table;
5647
5647
    if (res)
5648
5648
      return true;
5715
5715
}
5716
5716
 
5717
5717
 
5718
 
void resolve_const_item(THD *thd, Item **ref, Item *comp_item)
 
5718
void resolve_const_item(Session *session, Item **ref, Item *comp_item)
5719
5719
{
5720
5720
  Item *item= *ref;
5721
5721
  Item *new_item= NULL;
5775
5775
    assert(item_row->cols() == comp_item_row->cols());
5776
5776
    col= item_row->cols();
5777
5777
    while (col-- > 0)
5778
 
      resolve_const_item(thd, item_row->addr(col),
 
5778
      resolve_const_item(session, item_row->addr(col),
5779
5779
                         comp_item_row->element_index(col));
5780
5780
    break;
5781
5781
  }
5804
5804
    assert(0);
5805
5805
  }
5806
5806
  if (new_item)
5807
 
    thd->change_item_tree(ref, new_item);
 
5807
    session->change_item_tree(ref, new_item);
5808
5808
}
5809
5809
 
5810
5810
/**
6049
6049
bool Item_cache_row::allocate(uint32_t num)
6050
6050
{
6051
6051
  item_count= num;
6052
 
  THD *thd= current_thd;
 
6052
  Session *session= current_session;
6053
6053
  return (!(values= 
6054
 
            (Item_cache **) thd->calloc(sizeof(Item_cache *)*item_count)));
 
6054
            (Item_cache **) session->calloc(sizeof(Item_cache *)*item_count)));
6055
6055
}
6056
6056
 
6057
6057
 
6131
6131
}
6132
6132
 
6133
6133
 
6134
 
Item_type_holder::Item_type_holder(THD *thd, Item *item)
6135
 
  :Item(thd, item), enum_set_typelib(0), fld_type(get_real_type(item))
 
6134
Item_type_holder::Item_type_holder(Session *session, Item *item)
 
6135
  :Item(session, item), enum_set_typelib(0), fld_type(get_real_type(item))
6136
6136
{
6137
6137
  assert(item->fixed);
6138
6138
  maybe_null= item->maybe_null;
6227
6227
  Find field type which can carry current Item_type_holder type and
6228
6228
  type of given Item.
6229
6229
 
6230
 
  @param thd     thread handler
 
6230
  @param session     thread handler
6231
6231
  @param item    given item to join its parameters with this item ones
6232
6232
 
6233
6233
  @retval
6236
6236
    false  OK
6237
6237
*/
6238
6238
 
6239
 
bool Item_type_holder::join_types(THD *thd __attribute__((unused)),
 
6239
bool Item_type_holder::join_types(Session *session __attribute__((unused)),
6240
6240
                                  Item *item)
6241
6241
{
6242
6242
  uint32_t max_length_orig= max_length;
6468
6468
    do nothing
6469
6469
*/
6470
6470
 
6471
 
void dummy_error_processor(THD *thd __attribute__((unused)),
 
6471
void dummy_error_processor(Session *session __attribute__((unused)),
6472
6472
                           void *data __attribute__((unused)))
6473
6473
{}
6474
6474