~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/sql_show.cc

  • Committer: Monty Taylor
  • Date: 2008-10-23 23:53:49 UTC
  • mto: This revision was merged to the branch mainline in revision 557.
  • Revision ID: monty@inaugust.com-20081023235349-317wgwqwgccuacmq
SplitĀ outĀ nested_join.h.

Show diffs side-by-side

added added

removed removed

Lines of Context:
18
18
#include <drizzled/server_includes.h>
19
19
#include <drizzled/sql_select.h>
20
20
#include <drizzled/sql_show.h>
21
 
#include "repl_failsafe.h"
22
21
#include <mysys/my_dir.h>
23
 
#include <libdrizzle/gettext.h>
 
22
#include <drizzled/gettext.h>
 
23
#include <drizzled/util/convert.h>
 
24
#include <drizzled/error.h>
 
25
#include <string>
24
26
 
25
27
inline const char *
26
28
str_or_nil(const char *str)
31
33
/* Match the values of enum ha_choice */
32
34
static const char *ha_choice_values[] = {"", "0", "1"};
33
35
 
34
 
static void store_key_options(THD *thd, String *packet, Table *table,
 
36
static void store_key_options(Session *session, String *packet, Table *table,
35
37
                              KEY *key_info);
36
38
 
37
39
 
86
88
** List all table types supported
87
89
***************************************************************************/
88
90
 
89
 
static bool show_plugins(THD *thd, plugin_ref plugin,
 
91
static bool show_plugins(Session *session, plugin_ref plugin,
90
92
                            void *arg)
91
93
{
92
94
  Table *table= (Table*) arg;
168
170
  }
169
171
  table->field[7]->set_notnull();
170
172
 
171
 
  return schema_table_store_record(thd, table);
 
173
  return schema_table_store_record(session, table);
172
174
}
173
175
 
174
176
 
175
 
int fill_plugins(THD *thd, TableList *tables, COND *cond __attribute__((unused)))
 
177
int fill_plugins(Session *session, TableList *tables, COND *cond __attribute__((unused)))
176
178
{
177
179
  Table *table= tables->table;
178
180
 
179
 
  if (plugin_foreach_with_mask(thd, show_plugins, DRIZZLE_ANY_PLUGIN,
 
181
  if (plugin_foreach_with_mask(session, show_plugins, DRIZZLE_ANY_PLUGIN,
180
182
                               ~PLUGIN_IS_FREED, table))
181
183
    return(1);
182
184
 
189
191
 
190
192
  SYNOPSIS
191
193
    find_files()
192
 
    thd                 thread handler
 
194
    session                 thread handler
193
195
    files               put found files in this list
194
196
    db                  database name to set in TableList structure
195
197
    path                path to database
205
207
 
206
208
 
207
209
find_files_result
208
 
find_files(THD *thd, List<LEX_STRING> *files, const char *db,
 
210
find_files(Session *session, List<LEX_STRING> *files, const char *db,
209
211
           const char *path, const char *wild, bool dir)
210
212
{
211
213
  uint32_t i;
263
265
      if (wild && wild_compare(uname, wild, 0))
264
266
        continue;
265
267
      if (!(file_name= 
266
 
            thd->make_lex_string(file_name, uname, file_name_len, true)))
 
268
            session->make_lex_string(file_name, uname, file_name_len, true)))
267
269
      {
268
270
        my_dirend(dirp);
269
271
        return(FIND_FILES_OOM);
289
291
      }
290
292
    }
291
293
    if (!(file_name= 
292
 
          thd->make_lex_string(file_name, uname, file_name_len, true)) ||
 
294
          session->make_lex_string(file_name, uname, file_name_len, true)) ||
293
295
        files->push_back(file_name))
294
296
    {
295
297
      my_dirend(dirp);
303
305
 
304
306
 
305
307
bool
306
 
mysqld_show_create(THD *thd, TableList *table_list)
 
308
mysqld_show_create(Session *session, TableList *table_list)
307
309
{
308
 
  Protocol *protocol= thd->protocol;
 
310
  Protocol *protocol= session->protocol;
309
311
  char buff[2048];
310
312
  String buffer(buff, sizeof(buff), system_charset_info);
311
313
 
312
314
  /* Only one table for now, but VIEW can involve several tables */
313
 
  if (open_normal_and_derived_tables(thd, table_list, 0))
 
315
  if (open_normal_and_derived_tables(session, table_list, 0))
314
316
  {
315
 
    if (thd->is_error() && thd->main_da.sql_errno() != ER_VIEW_INVALID)
 
317
    if (session->is_error() && session->main_da.sql_errno() != ER_VIEW_INVALID)
316
318
      return(true);
317
319
 
318
320
    /*
320
322
      issue a warning with 'warning' level status in 
321
323
      case of invalid view and last error is ER_VIEW_INVALID
322
324
    */
323
 
    drizzle_reset_errors(thd, true);
324
 
    thd->clear_error();
 
325
    drizzle_reset_errors(session, true);
 
326
    session->clear_error();
325
327
  }
326
328
 
327
329
  buffer.length(0);
328
330
 
329
 
  if (store_create_info(thd, table_list, &buffer, NULL))
 
331
  if (store_create_info(session, table_list, &buffer, NULL))
330
332
    return(true);
331
333
 
332
334
  List<Item> field_list;
354
356
  if (protocol->write())
355
357
    return(true);
356
358
 
357
 
  my_eof(thd);
 
359
  my_eof(session);
358
360
  return(false);
359
361
}
360
362
 
361
 
bool mysqld_show_create_db(THD *thd, char *dbname,
 
363
bool mysqld_show_create_db(Session *session, char *dbname,
362
364
                           HA_CREATE_INFO *create_info)
363
365
{
364
366
  char buff[2048];
365
367
  String buffer(buff, sizeof(buff), system_charset_info);
366
 
  Protocol *protocol=thd->protocol;
 
368
  Protocol *protocol=session->protocol;
367
369
 
368
 
  if (store_db_create_info(thd, dbname, &buffer, create_info))
 
370
  if (store_db_create_info(session, dbname, &buffer, create_info))
369
371
  {
370
372
    /* 
371
373
      This assumes that the only reason for which store_db_create_info()
389
391
 
390
392
  if (protocol->write())
391
393
    return(true);
392
 
  my_eof(thd);
 
394
  my_eof(session);
393
395
  return(false);
394
396
}
395
397
 
401
403
****************************************************************************/
402
404
 
403
405
void
404
 
mysqld_list_fields(THD *thd, TableList *table_list, const char *wild)
 
406
mysqld_list_fields(Session *session, TableList *table_list, const char *wild)
405
407
{
406
408
  Table *table;
407
409
 
408
 
  if (open_normal_and_derived_tables(thd, table_list, 0))
 
410
  if (open_normal_and_derived_tables(session, table_list, 0))
409
411
    return;
410
412
  table= table_list->table;
411
413
 
422
424
  }
423
425
  restore_record(table, s->default_values);              // Get empty record
424
426
  table->use_all_columns();
425
 
  if (thd->protocol->send_fields(&field_list, Protocol::SEND_DEFAULTS))
 
427
  if (session->protocol->send_fields(&field_list, Protocol::SEND_DEFAULTS))
426
428
    return;
427
 
  my_eof(thd);
 
429
  my_eof(session);
428
430
  return;
429
431
}
430
432
 
470
472
 
471
473
  SYNOPSIS
472
474
  append_identifier()
473
 
  thd                   thread handler
 
475
  session                   thread handler
474
476
  packet                target string
475
477
  name                  the identifier to be appended
476
478
  name_length           length of the appending identifier
477
479
*/
478
480
 
479
481
void
480
 
append_identifier(THD *thd, String *packet, const char *name, uint32_t length)
 
482
append_identifier(Session *session, String *packet, const char *name, uint32_t length)
481
483
{
482
484
  const char *name_end;
483
485
  char quote_char;
484
 
  int q= get_quote_char_for_identifier(thd, name, length);
 
486
  int q= get_quote_char_for_identifier(session, name, length);
485
487
 
486
488
  if (q == EOF)
487
489
  {
524
526
 
525
527
  SYNOPSIS
526
528
    get_quote_char_for_identifier()
527
 
    thd         Thread handler
 
529
    session             Thread handler
528
530
    name        name to quote
529
531
    length      length of name
530
532
 
542
544
    #     Quote character
543
545
*/
544
546
 
545
 
int get_quote_char_for_identifier(THD *thd, const char *name, uint32_t length)
 
547
int get_quote_char_for_identifier(Session *session, const char *name, uint32_t length)
546
548
{
547
549
  if (length &&
548
550
      !is_keyword(name,length) &&
549
551
      !require_quotes(name, length) &&
550
 
      !(thd->options & OPTION_QUOTE_SHOW_CREATE))
 
552
      !(session->options & OPTION_QUOTE_SHOW_CREATE))
551
553
    return EOF;
552
554
  return '`';
553
555
}
555
557
 
556
558
/* Append directory name (if exists) to CREATE INFO */
557
559
 
558
 
static void append_directory(THD *thd __attribute__((unused)),
 
560
static void append_directory(Session *session __attribute__((unused)),
559
561
                             String *packet, const char *dir_type,
560
562
                             const char *filename)
561
563
{
573
575
 
574
576
#define LIST_PROCESS_HOST_LEN 64
575
577
 
576
 
static bool get_field_default_value(THD *thd __attribute__((unused)),
 
578
static bool get_field_default_value(Session *session __attribute__((unused)),
577
579
                                    Field *timestamp_field,
578
580
                                    Field *field, String *def_value,
579
581
                                    bool quoted)
632
634
 
633
635
  SYNOPSIS
634
636
    store_create_info()
635
 
    thd               The thread
 
637
    session               The thread
636
638
    table_list        A list containing one table to write statement
637
639
                      for.
638
640
    packet            Pointer to a string where statement will be
650
652
    0       OK
651
653
 */
652
654
 
653
 
int store_create_info(THD *thd, TableList *table_list, String *packet,
 
655
int store_create_info(Session *session, TableList *table_list, String *packet,
654
656
                      HA_CREATE_INFO *create_info_arg)
655
657
{
656
658
  List<Item> field_list;
657
 
  char tmp[MAX_FIELD_WIDTH], *for_str, buff[128], def_value_buf[MAX_FIELD_WIDTH];
 
659
  char tmp[MAX_FIELD_WIDTH], *for_str, def_value_buf[MAX_FIELD_WIDTH];
658
660
  const char *alias;
 
661
  std::string buff;
659
662
  String type(tmp, sizeof(tmp), system_charset_info);
660
663
  String def_value(def_value_buf, sizeof(def_value_buf), system_charset_info);
661
664
  Field **ptr,*field;
688
691
      alias= share->table_name.str;
689
692
    }
690
693
  }
691
 
  append_identifier(thd, packet, alias, strlen(alias));
 
694
  append_identifier(session, packet, alias, strlen(alias));
692
695
  packet->append(STRING_WITH_LEN(" (\n"));
693
696
  /*
694
697
    We need this to get default values from the table
705
708
      packet->append(STRING_WITH_LEN(",\n"));
706
709
 
707
710
    packet->append(STRING_WITH_LEN("  "));
708
 
    append_identifier(thd,packet,field->field_name, strlen(field->field_name));
 
711
    append_identifier(session,packet,field->field_name, strlen(field->field_name));
709
712
    packet->append(' ');
710
713
    // check for surprises from the previous call to Field::sql_type()
711
714
    if (type.ptr() != tmp)
713
716
    else
714
717
      type.set_charset(system_charset_info);
715
718
 
 
719
    if (field->vcol_info)
 
720
    {
 
721
      packet->append(STRING_WITH_LEN("VIRTUAL "));
 
722
    }
 
723
 
716
724
    field->sql_type(type);
717
725
    packet->append(type.ptr(), type.length(), system_charset_info);
718
726
 
 
727
    if (field->vcol_info)
 
728
    {
 
729
      packet->append(STRING_WITH_LEN(" AS ("));
 
730
      packet->append(field->vcol_info->expr_str.str,
 
731
                     field->vcol_info->expr_str.length,
 
732
                     system_charset_info);
 
733
      packet->append(STRING_WITH_LEN(")"));
 
734
      if (field->is_stored)
 
735
        packet->append(STRING_WITH_LEN(" STORED"));
 
736
    }
 
737
    
719
738
    if (field->has_charset())
720
739
    {
721
740
      if (field->charset() != share->table_charset)
762
781
          packet->append(STRING_WITH_LEN(" DYNAMIC */"));
763
782
      }
764
783
    }
765
 
    if (get_field_default_value(thd, table->timestamp_field,
 
784
    if (!field->vcol_info &&
 
785
        get_field_default_value(session, table->timestamp_field,
766
786
                                field, &def_value, 1))
767
787
    {
768
788
      packet->append(STRING_WITH_LEN(" DEFAULT "));
810
830
      packet->append(STRING_WITH_LEN("KEY "));
811
831
 
812
832
    if (!found_primary)
813
 
     append_identifier(thd, packet, key_info->name, strlen(key_info->name));
 
833
     append_identifier(session, packet, key_info->name, strlen(key_info->name));
814
834
 
815
835
    packet->append(STRING_WITH_LEN(" ("));
816
836
 
820
840
        packet->append(',');
821
841
 
822
842
      if (key_part->field)
823
 
        append_identifier(thd,packet,key_part->field->field_name,
 
843
        append_identifier(session,packet,key_part->field->field_name,
824
844
                          strlen(key_part->field->field_name));
825
845
      if (key_part->field &&
826
846
          (key_part->length !=
827
847
           table->field[key_part->fieldnr-1]->key_length()))
828
848
      {
829
 
        char *end;
830
 
        buff[0] = '(';
831
 
        end= int10_to_str((long) key_part->length /
832
 
                          key_part->field->charset()->mbmaxlen,
833
 
                          buff + 1,10);
834
 
        *end++ = ')';
835
 
        packet->append(buff,(uint) (end-buff));
 
849
        buff= "(";
 
850
        buff= to_string(buff, (int32_t) key_part->length /
 
851
                              key_part->field->charset()->mbmaxlen);
 
852
        buff += ")";
 
853
        packet->append(buff.c_str(), buff.length());
836
854
      }
837
855
    }
838
856
    packet->append(')');
839
 
    store_key_options(thd, packet, table, key_info);
 
857
    store_key_options(session, packet, table, key_info);
840
858
  }
841
859
 
842
860
  /*
882
900
 
883
901
    if (create_info.auto_increment_value > 1)
884
902
    {
885
 
      char *end;
886
903
      packet->append(STRING_WITH_LEN(" AUTO_INCREMENT="));
887
 
      end= int64_t10_to_str(create_info.auto_increment_value, buff,10);
888
 
      packet->append(buff, (uint) (end - buff));
 
904
      buff= to_string(create_info.auto_increment_value);
 
905
      packet->append(buff.c_str(), buff.length());
889
906
    }
890
907
 
891
908
    if (share->min_rows)
892
909
    {
893
 
      char *end;
894
910
      packet->append(STRING_WITH_LEN(" MIN_ROWS="));
895
 
      end= int64_t10_to_str(share->min_rows, buff, 10);
896
 
      packet->append(buff, (uint) (end- buff));
 
911
      buff= to_string(share->min_rows);
 
912
      packet->append(buff.c_str(), buff.length());
897
913
    }
898
914
 
899
915
    if (share->max_rows && !table_list->schema_table)
900
916
    {
901
 
      char *end;
902
917
      packet->append(STRING_WITH_LEN(" MAX_ROWS="));
903
 
      end= int64_t10_to_str(share->max_rows, buff, 10);
904
 
      packet->append(buff, (uint) (end - buff));
 
918
      buff= to_string(share->max_rows);
 
919
      packet->append(buff.c_str(), buff.length());
905
920
    }
906
921
 
907
922
    if (share->avg_row_length)
908
923
    {
909
 
      char *end;
910
924
      packet->append(STRING_WITH_LEN(" AVG_ROW_LENGTH="));
911
 
      end= int64_t10_to_str(share->avg_row_length, buff,10);
912
 
      packet->append(buff, (uint) (end - buff));
 
925
      buff= to_string(share->avg_row_length);
 
926
      packet->append(buff.c_str(), buff.length());
913
927
    }
914
928
 
915
929
    if (share->db_create_options & HA_OPTION_PACK_KEYS)
938
952
    }
939
953
    if (table->s->key_block_size)
940
954
    {
941
 
      char *end;
942
955
      packet->append(STRING_WITH_LEN(" KEY_BLOCK_SIZE="));
943
 
      end= int64_t10_to_str(table->s->key_block_size, buff, 10);
944
 
      packet->append(buff, (uint) (end - buff));
 
956
      buff= to_string(table->s->key_block_size);
 
957
      packet->append(buff.c_str(), buff.length());
945
958
    }
946
959
    if (share->block_size)
947
960
    {
948
 
      char *end;
949
961
      packet->append(STRING_WITH_LEN(" BLOCK_SIZE="));
950
 
      end= int64_t10_to_str(share->block_size, buff,10);
951
 
      packet->append(buff, (uint) (end - buff));
 
962
      buff= to_string(share->block_size);
 
963
      packet->append(buff.c_str(), buff.length());
952
964
    }
953
965
    table->file->append_create_info(packet);
954
966
    if (share->comment.length)
961
973
      packet->append(STRING_WITH_LEN(" CONNECTION="));
962
974
      append_unescaped(packet, share->connect_string.str, share->connect_string.length);
963
975
    }
964
 
    append_directory(thd, packet, "DATA",  create_info.data_file_name);
965
 
    append_directory(thd, packet, "INDEX", create_info.index_file_name);
 
976
    append_directory(session, packet, "DATA",  create_info.data_file_name);
 
977
    append_directory(session, packet, "INDEX", create_info.index_file_name);
966
978
  }
967
979
  table->restore_column_map(old_map);
968
980
  return(0);
981
993
  the resulting CREATE statement contains "IF NOT EXISTS" clause. Other flags
982
994
  in @c create_options are ignored.
983
995
 
984
 
  @param  thd           The current thread instance.
 
996
  @param  session           The current thread instance.
985
997
  @param  dbname        The name of the database.
986
998
  @param  buffer        A String instance where the statement is stored.
987
999
  @param  create_info   If not NULL, the options member influences the resulting 
990
1002
  @returns true if errors are detected, false otherwise.
991
1003
*/
992
1004
 
993
 
bool store_db_create_info(THD *thd, const char *dbname, String *buffer,
 
1005
bool store_db_create_info(Session *session, const char *dbname, String *buffer,
994
1006
                          HA_CREATE_INFO *create_info)
995
1007
{
996
1008
  HA_CREATE_INFO create;
1007
1019
    if (check_db_dir_existence(dbname))
1008
1020
      return(true);
1009
1021
 
1010
 
    load_db_opt_by_name(thd, dbname, &create);
 
1022
    load_db_opt_by_name(session, dbname, &create);
1011
1023
  }
1012
1024
 
1013
1025
  buffer->length(0);
1018
1030
  if (create_options & HA_LEX_CREATE_IF_NOT_EXISTS)
1019
1031
    buffer->append(STRING_WITH_LEN("/*!32312 IF NOT EXISTS*/ "));
1020
1032
 
1021
 
  append_identifier(thd, buffer, dbname, strlen(dbname));
 
1033
  append_identifier(session, buffer, dbname, strlen(dbname));
1022
1034
 
1023
1035
  if (create.default_table_charset)
1024
1036
  {
1036
1048
  return(false);
1037
1049
}
1038
1050
 
1039
 
static void store_key_options(THD *thd __attribute__((unused)),
 
1051
static void store_key_options(Session *session __attribute__((unused)),
1040
1052
                              String *packet, Table *table,
1041
1053
                              KEY *key_info)
1042
1054
{
1093
1105
template class I_List<thread_info>;
1094
1106
#endif
1095
1107
 
1096
 
void mysqld_list_processes(THD *thd,const char *user, bool verbose)
 
1108
void mysqld_list_processes(Session *session,const char *user, bool verbose)
1097
1109
{
1098
1110
  Item *field;
1099
1111
  List<Item> field_list;
1100
1112
  I_List<thread_info> thread_infos;
1101
 
  ulong max_query_length= (verbose ? thd->variables.max_allowed_packet :
 
1113
  ulong max_query_length= (verbose ? session->variables.max_allowed_packet :
1102
1114
                           PROCESS_LIST_WIDTH);
1103
 
  Protocol *protocol= thd->protocol;
 
1115
  Protocol *protocol= session->protocol;
1104
1116
 
1105
1117
  field_list.push_back(new Item_int("Id", 0, MY_INT32_NUM_DECIMAL_DIGITS));
1106
1118
  field_list.push_back(new Item_empty_string("User",16));
1118
1130
    return;
1119
1131
 
1120
1132
  pthread_mutex_lock(&LOCK_thread_count); // For unlink from list
1121
 
  if (!thd->killed)
 
1133
  if (!session->killed)
1122
1134
  {
1123
 
    I_List_iterator<THD> it(threads);
1124
 
    THD *tmp;
 
1135
    I_List_iterator<Session> it(threads);
 
1136
    Session *tmp;
1125
1137
    while ((tmp=it++))
1126
1138
    {
1127
1139
      Security_context *tmp_sctx= tmp->security_ctx;
1128
1140
      struct st_my_thread_var *mysys_var;
1129
1141
      if ((tmp->vio_ok() || tmp->system_thread) && (!user || (tmp_sctx->user && !strcmp(tmp_sctx->user, user))))
1130
1142
      {
1131
 
        thread_info *thd_info= new thread_info;
 
1143
        thread_info *session_info= new thread_info;
1132
1144
 
1133
 
        thd_info->thread_id=tmp->thread_id;
1134
 
        thd_info->user= thd->strdup(tmp_sctx->user ? tmp_sctx->user :
 
1145
        session_info->thread_id=tmp->thread_id;
 
1146
        session_info->user= session->strdup(tmp_sctx->user ? tmp_sctx->user :
1135
1147
                                    (tmp->system_thread ?
1136
1148
                                     "system user" : "unauthenticated user"));
1137
 
        thd_info->host= thd->strdup(tmp_sctx->ip);
1138
 
        if ((thd_info->db=tmp->db))             // Safe test
1139
 
          thd_info->db=thd->strdup(thd_info->db);
1140
 
        thd_info->command=(int) tmp->command;
 
1149
        session_info->host= session->strdup(tmp_sctx->ip);
 
1150
        if ((session_info->db=tmp->db))             // Safe test
 
1151
          session_info->db=session->strdup(session_info->db);
 
1152
        session_info->command=(int) tmp->command;
1141
1153
        if ((mysys_var= tmp->mysys_var))
1142
1154
          pthread_mutex_lock(&mysys_var->mutex);
1143
 
        thd_info->proc_info= (char*) (tmp->killed == THD::KILL_CONNECTION? "Killed" : 0);
1144
 
        thd_info->state_info= (char*) (tmp->net.reading_or_writing ?
 
1155
        session_info->proc_info= (char*) (tmp->killed == Session::KILL_CONNECTION? "Killed" : 0);
 
1156
        session_info->state_info= (char*) (tmp->net.reading_or_writing ?
1145
1157
                                       (tmp->net.reading_or_writing == 2 ?
1146
1158
                                        "Writing to net" :
1147
 
                                        thd_info->command == COM_SLEEP ? NULL :
 
1159
                                        session_info->command == COM_SLEEP ? NULL :
1148
1160
                                        "Reading from net") :
1149
1161
                                       tmp->get_proc_info() ? tmp->get_proc_info() :
1150
1162
                                       tmp->mysys_var &&
1153
1165
        if (mysys_var)
1154
1166
          pthread_mutex_unlock(&mysys_var->mutex);
1155
1167
 
1156
 
        thd_info->start_time= tmp->start_time;
1157
 
        thd_info->query=0;
 
1168
        session_info->start_time= tmp->start_time;
 
1169
        session_info->query=0;
1158
1170
        if (tmp->query)
1159
1171
        {
1160
1172
          /* 
1163
1175
            races with query_length
1164
1176
          */
1165
1177
          uint32_t length= cmin((uint32_t)max_query_length, tmp->query_length);
1166
 
          thd_info->query=(char*) thd->strmake(tmp->query,length);
 
1178
          session_info->query=(char*) session->strmake(tmp->query,length);
1167
1179
        }
1168
 
        thread_infos.append(thd_info);
 
1180
        thread_infos.append(session_info);
1169
1181
      }
1170
1182
    }
1171
1183
  }
1172
1184
  pthread_mutex_unlock(&LOCK_thread_count);
1173
1185
 
1174
 
  thread_info *thd_info;
 
1186
  thread_info *session_info;
1175
1187
  time_t now= my_time(0);
1176
 
  while ((thd_info=thread_infos.get()))
 
1188
  while ((session_info=thread_infos.get()))
1177
1189
  {
1178
1190
    protocol->prepare_for_resend();
1179
 
    protocol->store((uint64_t) thd_info->thread_id);
1180
 
    protocol->store(thd_info->user, system_charset_info);
1181
 
    protocol->store(thd_info->host, system_charset_info);
1182
 
    protocol->store(thd_info->db, system_charset_info);
1183
 
    if (thd_info->proc_info)
1184
 
      protocol->store(thd_info->proc_info, system_charset_info);
 
1191
    protocol->store((uint64_t) session_info->thread_id);
 
1192
    protocol->store(session_info->user, system_charset_info);
 
1193
    protocol->store(session_info->host, system_charset_info);
 
1194
    protocol->store(session_info->db, system_charset_info);
 
1195
    if (session_info->proc_info)
 
1196
      protocol->store(session_info->proc_info, system_charset_info);
1185
1197
    else
1186
 
      protocol->store(command_name[thd_info->command].str, system_charset_info);
1187
 
    if (thd_info->start_time)
1188
 
      protocol->store((uint32_t) (now - thd_info->start_time));
 
1198
      protocol->store(command_name[session_info->command].str, system_charset_info);
 
1199
    if (session_info->start_time)
 
1200
      protocol->store((uint32_t) (now - session_info->start_time));
1189
1201
    else
1190
1202
      protocol->store_null();
1191
 
    protocol->store(thd_info->state_info, system_charset_info);
1192
 
    protocol->store(thd_info->query, system_charset_info);
 
1203
    protocol->store(session_info->state_info, system_charset_info);
 
1204
    protocol->store(session_info->query, system_charset_info);
1193
1205
    if (protocol->write())
1194
1206
      break; /* purecov: inspected */
1195
1207
  }
1196
 
  my_eof(thd);
 
1208
  my_eof(session);
1197
1209
  return;
1198
1210
}
1199
1211
 
1200
 
int fill_schema_processlist(THD* thd, TableList* tables,
 
1212
int fill_schema_processlist(Session* session, TableList* tables,
1201
1213
                            COND* cond __attribute__((unused)))
1202
1214
{
1203
1215
  Table *table= tables->table;
1209
1221
 
1210
1222
  pthread_mutex_lock(&LOCK_thread_count);
1211
1223
 
1212
 
  if (!thd->killed)
 
1224
  if (!session->killed)
1213
1225
  {
1214
 
    I_List_iterator<THD> it(threads);
1215
 
    THD* tmp;
 
1226
    I_List_iterator<Session> it(threads);
 
1227
    Session* tmp;
1216
1228
 
1217
1229
    while ((tmp= it++))
1218
1230
    {
1242
1254
      if ((mysys_var= tmp->mysys_var))
1243
1255
        pthread_mutex_lock(&mysys_var->mutex);
1244
1256
      /* COMMAND */
1245
 
      if ((val= (char *) (tmp->killed == THD::KILL_CONNECTION? "Killed" : 0)))
 
1257
      if ((val= (char *) (tmp->killed == Session::KILL_CONNECTION? "Killed" : 0)))
1246
1258
        table->field[4]->store(val, strlen(val), cs);
1247
1259
      else
1248
1260
        table->field[4]->store(command_name[tmp->command].str,
1278
1290
        table->field[7]->set_notnull();
1279
1291
      }
1280
1292
 
1281
 
      if (schema_table_store_record(thd, table))
 
1293
      if (schema_table_store_record(session, table))
1282
1294
      {
1283
1295
        pthread_mutex_unlock(&LOCK_thread_count);
1284
1296
        return(1);
1469
1481
    *buf= my_toupper(system_charset_info, *buf);
1470
1482
}
1471
1483
 
1472
 
static bool show_status_array(THD *thd, const char *wild,
 
1484
static bool show_status_array(Session *session, const char *wild,
1473
1485
                              SHOW_VAR *variables,
1474
1486
                              enum enum_var_type value_type,
1475
1487
                              struct system_status_var *status_var,
1505
1517
      Repeat as necessary, if new var is again SHOW_FUNC
1506
1518
    */
1507
1519
    for (var=variables; var->type == SHOW_FUNC; var= &tmp)
1508
 
      ((mysql_show_var_func)((st_show_var_func_container *)var->value)->func)(thd, &tmp, buff);
 
1520
      ((mysql_show_var_func)((st_show_var_func_container *)var->value)->func)(session, &tmp, buff);
1509
1521
 
1510
1522
    SHOW_TYPE show_type=var->type;
1511
1523
    if (show_type == SHOW_ARRAY)
1512
1524
    {
1513
 
      show_status_array(thd, wild, (SHOW_VAR *) var->value, value_type,
 
1525
      show_status_array(session, wild, (SHOW_VAR *) var->value, value_type,
1514
1526
                        status_var, name_buffer, table, ucase_names);
1515
1527
    }
1516
1528
    else
1526
1538
        if (show_type == SHOW_SYS)
1527
1539
        {
1528
1540
          show_type= ((sys_var*) value)->show_type();
1529
 
          value=     (char*) ((sys_var*) value)->value_ptr(thd, value_type,
 
1541
          value=     (char*) ((sys_var*) value)->value_ptr(session, value_type,
1530
1542
                                                           &null_lex_str);
1531
1543
        }
1532
1544
 
1612
1624
 
1613
1625
        pthread_mutex_unlock(&LOCK_global_system_variables);
1614
1626
 
1615
 
        if (schema_table_store_record(thd, table))
 
1627
        if (schema_table_store_record(session, table))
1616
1628
          return(true);
1617
1629
      }
1618
1630
    }
1630
1642
  /* Ensure that thread id not killed during loop */
1631
1643
  pthread_mutex_lock(&LOCK_thread_count); // For unlink from list
1632
1644
 
1633
 
  I_List_iterator<THD> it(threads);
1634
 
  THD *tmp;
 
1645
  I_List_iterator<Session> it(threads);
 
1646
  Session *tmp;
1635
1647
  
1636
1648
  /* Get global values as base */
1637
1649
  *to= global_status_var;
1661
1673
 
1662
1674
  SYNOPSIS
1663
1675
    schema_table_store_record()
1664
 
    thd                   thread handler
 
1676
    session                   thread handler
1665
1677
    table                 Information schema table to be updated
1666
1678
 
1667
1679
  RETURN
1669
1681
    1                     error
1670
1682
*/
1671
1683
 
1672
 
bool schema_table_store_record(THD *thd, Table *table)
 
1684
bool schema_table_store_record(Session *session, Table *table)
1673
1685
{
1674
1686
  int error;
1675
1687
  if ((error= table->file->ha_write_row(table->record[0])))
1676
1688
  {
1677
1689
    TMP_TABLE_PARAM *param= table->pos_in_table_list->schema_table_param;
1678
1690
 
1679
 
    if (create_myisam_from_heap(thd, table, param->start_recinfo, 
 
1691
    if (create_myisam_from_heap(session, table, param->start_recinfo, 
1680
1692
                                &param->recinfo, error, 0))
1681
1693
      return 1;
1682
1694
  }
1684
1696
}
1685
1697
 
1686
1698
 
1687
 
int make_table_list(THD *thd, SELECT_LEX *sel,
 
1699
int make_table_list(Session *session, SELECT_LEX *sel,
1688
1700
                    LEX_STRING *db_name, LEX_STRING *table_name)
1689
1701
{
1690
1702
  Table_ident *table_ident;
1691
 
  table_ident= new Table_ident(thd, *db_name, *table_name, 1);
 
1703
  table_ident= new Table_ident(session, *db_name, *table_name, 1);
1692
1704
  sel->init_query();
1693
 
  if (!sel->add_table_to_list(thd, table_ident, 0, 0, TL_READ))
 
1705
  if (!sel->add_table_to_list(session, table_ident, 0, 0, TL_READ))
1694
1706
    return 1;
1695
1707
  return 0;
1696
1708
}
1704
1716
           fill appropriate lookup_field_vals struct field
1705
1717
           with this value.
1706
1718
 
1707
 
  @param[in]      thd                   thread handler
 
1719
  @param[in]      session                   thread handler
1708
1720
  @param[in]      item_func             part of WHERE condition
1709
1721
  @param[in]      table                 I_S table
1710
1722
  @param[in, out] lookup_field_vals     Struct which holds lookup values 
1714
1726
    1             error, there can be no matching records for the condition
1715
1727
*/
1716
1728
 
1717
 
bool get_lookup_value(THD *thd, Item_func *item_func,
 
1729
bool get_lookup_value(Session *session, Item_func *item_func,
1718
1730
                      TableList *table, 
1719
1731
                      LOOKUP_FIELD_VALUES *lookup_field_vals)
1720
1732
{
1763
1775
                               (unsigned char *) item_field->field_name,
1764
1776
                               strlen(item_field->field_name), 0))
1765
1777
    {
1766
 
      thd->make_lex_string(&lookup_field_vals->db_value, tmp_str->ptr(),
 
1778
      session->make_lex_string(&lookup_field_vals->db_value, tmp_str->ptr(),
1767
1779
                           tmp_str->length(), false);
1768
1780
    }
1769
1781
    /* Lookup value is table name */
1772
1784
                                    (unsigned char *) item_field->field_name,
1773
1785
                                    strlen(item_field->field_name), 0))
1774
1786
    {
1775
 
      thd->make_lex_string(&lookup_field_vals->table_value, tmp_str->ptr(),
 
1787
      session->make_lex_string(&lookup_field_vals->table_value, tmp_str->ptr(),
1776
1788
                           tmp_str->length(), false);
1777
1789
    }
1778
1790
  }
1787
1799
           from 'WHERE' condition if it's possible and 
1788
1800
           fill lookup_field_vals struct fields with these values.
1789
1801
 
1790
 
  @param[in]      thd                   thread handler
 
1802
  @param[in]      session                   thread handler
1791
1803
  @param[in]      cond                  WHERE condition
1792
1804
  @param[in]      table                 I_S table
1793
1805
  @param[in, out] lookup_field_vals     Struct which holds lookup values 
1797
1809
    1             error, there can be no matching records for the condition
1798
1810
*/
1799
1811
 
1800
 
bool calc_lookup_values_from_cond(THD *thd, COND *cond, TableList *table,
 
1812
bool calc_lookup_values_from_cond(Session *session, COND *cond, TableList *table,
1801
1813
                                  LOOKUP_FIELD_VALUES *lookup_field_vals)
1802
1814
{
1803
1815
  if (!cond)
1813
1825
      {
1814
1826
        if (item->type() == Item::FUNC_ITEM)
1815
1827
        {
1816
 
          if (get_lookup_value(thd, (Item_func*)item, table, lookup_field_vals))
 
1828
          if (get_lookup_value(session, (Item_func*)item, table, lookup_field_vals))
1817
1829
            return 1;
1818
1830
        }
1819
1831
        else
1820
1832
        {
1821
 
          if (calc_lookup_values_from_cond(thd, item, table, lookup_field_vals))
 
1833
          if (calc_lookup_values_from_cond(session, item, table, lookup_field_vals))
1822
1834
            return 1;
1823
1835
        }
1824
1836
      }
1826
1838
    return 0;
1827
1839
  }
1828
1840
  else if (cond->type() == Item::FUNC_ITEM &&
1829
 
           get_lookup_value(thd, (Item_func*) cond, table, lookup_field_vals))
 
1841
           get_lookup_value(session, (Item_func*) cond, table, lookup_field_vals))
1830
1842
    return 1;
1831
1843
  return 0;
1832
1844
}
1936
1948
           from LEX struct and fill lookup_field_vals struct field
1937
1949
           with these values.
1938
1950
 
1939
 
  @param[in]      thd                   thread handler
 
1951
  @param[in]      session                   thread handler
1940
1952
  @param[in]      cond                  WHERE condition
1941
1953
  @param[in]      tables                I_S table
1942
1954
  @param[in, out] lookup_field_values   Struct which holds lookup values 
1946
1958
    1             error, there can be no matching records for the condition
1947
1959
*/
1948
1960
 
1949
 
bool get_lookup_field_values(THD *thd, COND *cond, TableList *tables,
 
1961
bool get_lookup_field_values(Session *session, COND *cond, TableList *tables,
1950
1962
                             LOOKUP_FIELD_VALUES *lookup_field_values)
1951
1963
{
1952
 
  LEX *lex= thd->lex;
 
1964
  LEX *lex= session->lex;
1953
1965
  const char *wild= lex->wild ? lex->wild->ptr() : NULL;
1954
1966
  memset(lookup_field_values, 0, sizeof(LOOKUP_FIELD_VALUES));
1955
1967
  switch (lex->sql_command) {
1977
1989
      The "default" is for queries over I_S.
1978
1990
      All previous cases handle SHOW commands.
1979
1991
    */
1980
 
    return calc_lookup_values_from_cond(thd, cond, tables, lookup_field_values);
 
1992
    return calc_lookup_values_from_cond(session, cond, tables, lookup_field_values);
1981
1993
  }
1982
1994
}
1983
1995
 
1993
2005
 
1994
2006
  SYNOPSIS
1995
2007
    make_db_list()
1996
 
    thd                   thread handler
 
2008
    session                   thread handler
1997
2009
    files                 list of db names
1998
2010
    wild                  wild string
1999
2011
    idx_field_vals        idx_field_vals->db_name contains db name or
2006
2018
    non-zero              error
2007
2019
*/
2008
2020
 
2009
 
int make_db_list(THD *thd, List<LEX_STRING> *files,
 
2021
int make_db_list(Session *session, List<LEX_STRING> *files,
2010
2022
                 LOOKUP_FIELD_VALUES *lookup_field_vals,
2011
2023
                 bool *with_i_schema)
2012
2024
{
2013
2025
  LEX_STRING *i_s_name_copy= 0;
2014
 
  i_s_name_copy= thd->make_lex_string(i_s_name_copy,
 
2026
  i_s_name_copy= session->make_lex_string(i_s_name_copy,
2015
2027
                                      INFORMATION_SCHEMA_NAME.str,
2016
2028
                                      INFORMATION_SCHEMA_NAME.length, true);
2017
2029
  *with_i_schema= 0;
2031
2043
      if (files->push_back(i_s_name_copy))
2032
2044
        return 1;
2033
2045
    }
2034
 
    return (find_files(thd, files, NULL, mysql_data_home,
 
2046
    return (find_files(session, files, NULL, mysql_data_home,
2035
2047
                       lookup_field_vals->db_value.str, 1) != FIND_FILES_OK);
2036
2048
  }
2037
2049
 
2062
2074
  if (files->push_back(i_s_name_copy))
2063
2075
    return 1;
2064
2076
  *with_i_schema= 1;
2065
 
  return (find_files(thd, files, NULL,
 
2077
  return (find_files(session, files, NULL,
2066
2078
                     mysql_data_home, NULL, 1) != FIND_FILES_OK);
2067
2079
}
2068
2080
 
2074
2086
};
2075
2087
 
2076
2088
 
2077
 
static bool add_schema_table(THD *thd, plugin_ref plugin,
 
2089
static bool add_schema_table(Session *session, plugin_ref plugin,
2078
2090
                                void* p_data)
2079
2091
{
2080
2092
  LEX_STRING *file_name= 0;
2098
2110
      return(0);
2099
2111
  }
2100
2112
 
2101
 
  if ((file_name= thd->make_lex_string(file_name, schema_table->table_name,
 
2113
  if ((file_name= session->make_lex_string(file_name, schema_table->table_name,
2102
2114
                                       strlen(schema_table->table_name),
2103
2115
                                       true)) &&
2104
2116
      !file_list->push_back(file_name))
2107
2119
}
2108
2120
 
2109
2121
 
2110
 
int schema_tables_add(THD *thd, List<LEX_STRING> *files, const char *wild)
 
2122
int schema_tables_add(Session *session, List<LEX_STRING> *files, const char *wild)
2111
2123
{
2112
2124
  LEX_STRING *file_name= 0;
2113
2125
  ST_SCHEMA_TABLE *tmp_schema_table= schema_tables;
2130
2142
        continue;
2131
2143
    }
2132
2144
    if ((file_name= 
2133
 
         thd->make_lex_string(file_name, tmp_schema_table->table_name,
 
2145
         session->make_lex_string(file_name, tmp_schema_table->table_name,
2134
2146
                              strlen(tmp_schema_table->table_name), true)) &&
2135
2147
        !files->push_back(file_name))
2136
2148
      continue;
2139
2151
 
2140
2152
  add_data.files= files;
2141
2153
  add_data.wild= wild;
2142
 
  if (plugin_foreach(thd, add_schema_table,
 
2154
  if (plugin_foreach(session, add_schema_table,
2143
2155
                     DRIZZLE_INFORMATION_SCHEMA_PLUGIN, &add_data))
2144
2156
    return(1);
2145
2157
 
2153
2165
  @details        The function creates the list of table names in
2154
2166
                  database
2155
2167
 
2156
 
  @param[in]      thd                   thread handler
 
2168
  @param[in]      session                   thread handler
2157
2169
  @param[in]      table_names           List of table names in database
2158
2170
  @param[in]      lex                   pointer to LEX struct
2159
2171
  @param[in]      lookup_field_vals     pointer to LOOKUP_FIELD_VALUE struct
2167
2179
*/
2168
2180
 
2169
2181
static int
2170
 
make_table_name_list(THD *thd, List<LEX_STRING> *table_names, LEX *lex,
 
2182
make_table_name_list(Session *session, List<LEX_STRING> *table_names, LEX *lex,
2171
2183
                     LOOKUP_FIELD_VALUES *lookup_field_vals,
2172
2184
                     bool with_i_schema, LEX_STRING *db_name)
2173
2185
{
2178
2190
  {
2179
2191
    if (with_i_schema)
2180
2192
    {
2181
 
      if (find_schema_table(thd, lookup_field_vals->table_value.str))
 
2193
      if (find_schema_table(session, lookup_field_vals->table_value.str))
2182
2194
      {
2183
2195
        if (table_names->push_back(&lookup_field_vals->table_value))
2184
2196
          return 1;
2197
2209
    to the list
2198
2210
  */
2199
2211
  if (with_i_schema)
2200
 
    return (schema_tables_add(thd, table_names,
 
2212
    return (schema_tables_add(session, table_names,
2201
2213
                              lookup_field_vals->table_value.str));
2202
2214
 
2203
 
  find_files_result res= find_files(thd, table_names, db_name->str, path,
 
2215
  find_files_result res= find_files(session, table_names, db_name->str, path,
2204
2216
                                    lookup_field_vals->table_value.str, 0);
2205
2217
  if (res != FIND_FILES_OK)
2206
2218
  {
2214
2226
    {
2215
2227
      if (lex->sql_command != SQLCOM_SELECT)
2216
2228
        return 1;
2217
 
      thd->clear_error();
 
2229
      session->clear_error();
2218
2230
      return 2;
2219
2231
    }
2220
2232
    return 1;
2226
2238
/**
2227
2239
  @brief          Fill I_S table for SHOW COLUMNS|INDEX commands
2228
2240
 
2229
 
  @param[in]      thd                      thread handler
 
2241
  @param[in]      session                      thread handler
2230
2242
  @param[in]      tables                   TableList for I_S table
2231
2243
  @param[in]      schema_table             pointer to I_S structure
2232
2244
  @param[in]      open_tables_state_backup pointer to Open_tables_state object
2240
2252
*/
2241
2253
 
2242
2254
static int 
2243
 
fill_schema_show_cols_or_idxs(THD *thd, TableList *tables,
 
2255
fill_schema_show_cols_or_idxs(Session *session, TableList *tables,
2244
2256
                              ST_SCHEMA_TABLE *schema_table,
2245
2257
                              Open_tables_state *open_tables_state_backup)
2246
2258
{
2247
 
  LEX *lex= thd->lex;
 
2259
  LEX *lex= session->lex;
2248
2260
  bool res;
2249
2261
  LEX_STRING tmp_lex_string, tmp_lex_string1, *db_name, *table_name;
2250
2262
  enum_sql_command save_sql_command= lex->sql_command;
2255
2267
 
2256
2268
  lex->all_selects_list= tables->schema_select_lex;
2257
2269
  /*
2258
 
    Restore thd->temporary_tables to be able to process
 
2270
    Restore session->temporary_tables to be able to process
2259
2271
    temporary tables(only for 'show index' & 'show columns').
2260
2272
    This should be changed when processing of temporary tables for
2261
2273
    I_S tables will be done.
2262
2274
  */
2263
 
  thd->temporary_tables= open_tables_state_backup->temporary_tables;
 
2275
  session->temporary_tables= open_tables_state_backup->temporary_tables;
2264
2276
  /*
2265
2277
    Let us set fake sql_command so views won't try to merge
2266
2278
    themselves into main statement. If we don't do this,
2268
2280
    SQLCOM_SHOW_FIELDS is used because it satisfies 'only_view_structure()' 
2269
2281
  */
2270
2282
  lex->sql_command= SQLCOM_SHOW_FIELDS;
2271
 
  res= open_normal_and_derived_tables(thd, show_table_list,
 
2283
  res= open_normal_and_derived_tables(session, show_table_list,
2272
2284
                                      DRIZZLE_LOCK_IGNORE_FLUSH);
2273
2285
  lex->sql_command= save_sql_command;
2274
2286
  /*
2282
2294
    in this case(this part of code is used only for 
2283
2295
    'show columns' & 'show statistics' commands).
2284
2296
  */
2285
 
   table_name= thd->make_lex_string(&tmp_lex_string1, show_table_list->alias,
 
2297
   table_name= session->make_lex_string(&tmp_lex_string1, show_table_list->alias,
2286
2298
                                    strlen(show_table_list->alias), false);
2287
 
   db_name= thd->make_lex_string(&tmp_lex_string, show_table_list->db,
 
2299
   db_name= session->make_lex_string(&tmp_lex_string, show_table_list->db,
2288
2300
                                 show_table_list->db_length, false);
2289
2301
      
2290
2302
 
2291
 
   error= test(schema_table->process_table(thd, show_table_list,
 
2303
   error= test(schema_table->process_table(session, show_table_list,
2292
2304
                                           table, res, db_name,
2293
2305
                                           table_name));
2294
 
   thd->temporary_tables= 0;
2295
 
   close_tables_for_reopen(thd, &show_table_list);
 
2306
   session->temporary_tables= 0;
 
2307
   close_tables_for_reopen(session, &show_table_list);
2296
2308
   return(error);
2297
2309
}
2298
2310
 
2300
2312
/**
2301
2313
  @brief          Fill I_S table for SHOW Table NAMES commands
2302
2314
 
2303
 
  @param[in]      thd                      thread handler
 
2315
  @param[in]      session                      thread handler
2304
2316
  @param[in]      table                    Table struct for I_S table
2305
2317
  @param[in]      db_name                  database name
2306
2318
  @param[in]      table_name               table name
2311
2323
    @retval       1           error
2312
2324
*/
2313
2325
 
2314
 
static int fill_schema_table_names(THD *thd, Table *table,
 
2326
static int fill_schema_table_names(Session *session, Table *table,
2315
2327
                                   LEX_STRING *db_name, LEX_STRING *table_name,
2316
2328
                                   bool with_i_schema)
2317
2329
{
2326
2338
    char path[FN_REFLEN];
2327
2339
    (void) build_table_filename(path, sizeof(path), db_name->str, 
2328
2340
                                table_name->str, reg_ext, 0);
2329
 
    if (mysql_frm_type(thd, path, &not_used)) 
 
2341
    if (mysql_frm_type(session, path, &not_used)) 
2330
2342
    {
2331
2343
      table->field[3]->store(STRING_WITH_LEN("BASE Table"),
2332
2344
                             system_charset_info);
2337
2349
                             system_charset_info);
2338
2350
    }
2339
2351
 
2340
 
    if (thd->is_error() && thd->main_da.sql_errno() == ER_NO_SUCH_TABLE)
 
2352
    if (session->is_error() && session->main_da.sql_errno() == ER_NO_SUCH_TABLE)
2341
2353
    {
2342
 
      thd->clear_error();
 
2354
      session->clear_error();
2343
2355
      return 0;
2344
2356
    }
2345
2357
  }
2346
 
  if (schema_table_store_record(thd, table))
 
2358
  if (schema_table_store_record(session, table))
2347
2359
    return 1;
2348
2360
  return 0;
2349
2361
}
2392
2404
/**
2393
2405
  @brief          Fill I_S table with data from FRM file only
2394
2406
 
2395
 
  @param[in]      thd                      thread handler
 
2407
  @param[in]      session                      thread handler
2396
2408
  @param[in]      table                    Table struct for I_S table
2397
2409
  @param[in]      schema_table             I_S table struct
2398
2410
  @param[in]      db_name                  database name
2406
2418
                              open_tables function for this table
2407
2419
*/
2408
2420
 
2409
 
static int fill_schema_table_from_frm(THD *thd,TableList *tables,
 
2421
static int fill_schema_table_from_frm(Session *session,TableList *tables,
2410
2422
                                      ST_SCHEMA_TABLE *schema_table,
2411
2423
                                      LEX_STRING *db_name,
2412
2424
                                      LEX_STRING *table_name,
2427
2439
  table_list.table_name= table_name->str;
2428
2440
  table_list.db= db_name->str;
2429
2441
 
2430
 
  key_length= create_table_def_key(thd, key, &table_list, 0);
 
2442
  key_length= create_table_def_key(session, key, &table_list, 0);
2431
2443
  pthread_mutex_lock(&LOCK_open);
2432
 
  share= get_table_share(thd, &table_list, key,
 
2444
  share= get_table_share(session, &table_list, key,
2433
2445
                         key_length, 0, &error);
2434
2446
  if (!share)
2435
2447
  {
2440
2452
  {
2441
2453
    tbl.s= share;
2442
2454
    table_list.table= &tbl;
2443
 
    res= schema_table->process_table(thd, &table_list, table,
 
2455
    res= schema_table->process_table(session, &table_list, table,
2444
2456
                                     res, db_name, table_name);
2445
2457
  }
2446
2458
 
2448
2460
 
2449
2461
err:
2450
2462
  pthread_mutex_unlock(&LOCK_open);
2451
 
  thd->clear_error();
 
2463
  session->clear_error();
2452
2464
  return res;
2453
2465
}
2454
2466
 
2464
2476
                  from frm files and storage engine are filled by the function
2465
2477
                  get_all_tables().
2466
2478
 
2467
 
  @param[in]      thd                      thread handler
 
2479
  @param[in]      session                      thread handler
2468
2480
  @param[in]      tables                   I_S table
2469
2481
  @param[in]      cond                     'WHERE' condition
2470
2482
 
2473
2485
    @retval       1                        error
2474
2486
*/
2475
2487
 
2476
 
int get_all_tables(THD *thd, TableList *tables, COND *cond)
 
2488
int get_all_tables(Session *session, TableList *tables, COND *cond)
2477
2489
{
2478
 
  LEX *lex= thd->lex;
 
2490
  LEX *lex= session->lex;
2479
2491
  Table *table= tables->table;
2480
2492
  SELECT_LEX *old_all_select_lex= lex->all_selects_list;
2481
2493
  enum_sql_command save_sql_command= lex->sql_command;
2494
2506
  Open_tables_state open_tables_state_backup;
2495
2507
  Query_tables_list query_tables_list_backup;
2496
2508
  uint32_t table_open_method;
2497
 
  bool old_value= thd->no_warnings_for_error;
 
2509
  bool old_value= session->no_warnings_for_error;
2498
2510
 
2499
2511
  lex->reset_n_backup_query_tables_list(&query_tables_list_backup);
2500
2512
 
2503
2515
    tables open and locked, since we won't lock tables which we will
2504
2516
    open and will ignore possible name-locks for these tables.
2505
2517
  */
2506
 
  thd->reset_n_backup_open_tables_state(&open_tables_state_backup);
 
2518
  session->reset_n_backup_open_tables_state(&open_tables_state_backup);
2507
2519
 
2508
2520
  schema_table_idx= get_schema_table_idx(schema_table);
2509
2521
  tables->table_open_method= table_open_method=
2515
2527
  */
2516
2528
  if (lsel && lsel->table_list.first)
2517
2529
  {
2518
 
    error= fill_schema_show_cols_or_idxs(thd, tables, schema_table,
 
2530
    error= fill_schema_show_cols_or_idxs(session, tables, schema_table,
2519
2531
                                         &open_tables_state_backup);
2520
2532
    goto err;
2521
2533
  }
2522
2534
 
2523
 
  if (get_lookup_field_values(thd, cond, tables, &lookup_field_vals))
 
2535
  if (get_lookup_field_values(session, cond, tables, &lookup_field_vals))
2524
2536
  {
2525
2537
    error= 0;
2526
2538
    goto err;
2559
2571
    goto err;
2560
2572
  }
2561
2573
 
2562
 
  if (make_db_list(thd, &db_names, &lookup_field_vals, &with_i_schema))
 
2574
  if (make_db_list(session, &db_names, &lookup_field_vals, &with_i_schema))
2563
2575
    goto err;
2564
2576
  it.rewind(); /* To get access to new elements in basis list */
2565
2577
  while ((db_name= it++))
2566
2578
  {
2567
2579
    {
2568
 
      thd->no_warnings_for_error= 1;
 
2580
      session->no_warnings_for_error= 1;
2569
2581
      List<LEX_STRING> table_names;
2570
 
      int res= make_table_name_list(thd, &table_names, lex,
 
2582
      int res= make_table_name_list(session, &table_names, lex,
2571
2583
                                    &lookup_field_vals,
2572
2584
                                    with_i_schema, db_name);
2573
2585
      if (res == 2)   /* Not fatal error, continue */
2596
2608
              (!lookup_field_vals.table_value.length ||
2597
2609
               lookup_field_vals.wild_table_value))
2598
2610
          {
2599
 
            if (schema_table_store_record(thd, table))
 
2611
            if (schema_table_store_record(session, table))
2600
2612
              goto err;      /* Out of space in temporary table */
2601
2613
            continue;
2602
2614
          }
2604
2616
          /* SHOW Table NAMES command */
2605
2617
          if (schema_table_idx == SCH_TABLE_NAMES)
2606
2618
          {
2607
 
            if (fill_schema_table_names(thd, tables->table, db_name,
 
2619
            if (fill_schema_table_names(session, tables->table, db_name,
2608
2620
                                        table_name, with_i_schema))
2609
2621
              continue;
2610
2622
          }
2613
2625
            if (!(table_open_method & ~OPEN_FRM_ONLY) &&
2614
2626
                !with_i_schema)
2615
2627
            {
2616
 
              if (!fill_schema_table_from_frm(thd, tables, schema_table, db_name,
 
2628
              if (!fill_schema_table_from_frm(session, tables, schema_table, db_name,
2617
2629
                                              table_name, schema_table_idx))
2618
2630
                continue;
2619
2631
            }
2624
2636
              Set the parent lex of 'sel' because it is needed by
2625
2637
              sel.init_query() which is called inside make_table_list.
2626
2638
            */
2627
 
            thd->no_warnings_for_error= 1;
 
2639
            session->no_warnings_for_error= 1;
2628
2640
            sel.parent_lex= lex;
2629
2641
            /* db_name can be changed in make_table_list() func */
2630
 
            if (!thd->make_lex_string(&orig_db_name, db_name->str,
 
2642
            if (!session->make_lex_string(&orig_db_name, db_name->str,
2631
2643
                                      db_name->length, false))
2632
2644
              goto err;
2633
 
            if (make_table_list(thd, &sel, db_name, table_name))
 
2645
            if (make_table_list(session, &sel, db_name, table_name))
2634
2646
              goto err;
2635
2647
            TableList *show_table_list= (TableList*) sel.table_list.first;
2636
2648
            lex->all_selects_list= &sel;
2638
2650
            lex->sql_command= SQLCOM_SHOW_FIELDS;
2639
2651
            show_table_list->i_s_requested_object=
2640
2652
              schema_table->i_s_requested_object;
2641
 
            res= open_normal_and_derived_tables(thd, show_table_list,
 
2653
            res= open_normal_and_derived_tables(session, show_table_list,
2642
2654
                                                DRIZZLE_LOCK_IGNORE_FLUSH);
2643
2655
            lex->sql_command= save_sql_command;
2644
2656
            /*
2645
2657
              XXX:  show_table_list has a flag i_is_requested,
2646
2658
              and when it's set, open_normal_and_derived_tables()
2647
2659
              can return an error without setting an error message
2648
 
              in THD, which is a hack. This is why we have to
2649
 
              check for res, then for thd->is_error() only then
2650
 
              for thd->main_da.sql_errno().
 
2660
              in Session, which is a hack. This is why we have to
 
2661
              check for res, then for session->is_error() only then
 
2662
              for session->main_da.sql_errno().
2651
2663
            */
2652
 
            if (res && thd->is_error() &&
2653
 
                thd->main_da.sql_errno() == ER_NO_SUCH_TABLE)
 
2664
            if (res && session->is_error() &&
 
2665
                session->main_da.sql_errno() == ER_NO_SUCH_TABLE)
2654
2666
            {
2655
2667
              /*
2656
2668
                Hide error for not existing table.
2659
2671
                table does not exist.
2660
2672
              */
2661
2673
              res= 0;
2662
 
              thd->clear_error();
 
2674
              session->clear_error();
2663
2675
            }
2664
2676
            else
2665
2677
            {
2670
2682
                to use alias because alias contains original table name 
2671
2683
                in this case.
2672
2684
              */
2673
 
              thd->make_lex_string(&tmp_lex_string, show_table_list->alias,
 
2685
              session->make_lex_string(&tmp_lex_string, show_table_list->alias,
2674
2686
                                   strlen(show_table_list->alias), false);
2675
 
              res= schema_table->process_table(thd, show_table_list, table,
 
2687
              res= schema_table->process_table(session, show_table_list, table,
2676
2688
                                               res, &orig_db_name,
2677
2689
                                               &tmp_lex_string);
2678
 
              close_tables_for_reopen(thd, &show_table_list);
 
2690
              close_tables_for_reopen(session, &show_table_list);
2679
2691
            }
2680
2692
            assert(!lex->query_tables_own_last);
2681
2693
            if (res)
2693
2705
 
2694
2706
  error= 0;
2695
2707
err:
2696
 
  thd->restore_backup_open_tables_state(&open_tables_state_backup);
 
2708
  session->restore_backup_open_tables_state(&open_tables_state_backup);
2697
2709
  lex->restore_backup_query_tables_list(&query_tables_list_backup);
2698
2710
  lex->derived_tables= derived_tables;
2699
2711
  lex->all_selects_list= old_all_select_lex;
2700
2712
  lex->sql_command= save_sql_command;
2701
 
  thd->no_warnings_for_error= old_value;
 
2713
  session->no_warnings_for_error= old_value;
2702
2714
  return(error);
2703
2715
}
2704
2716
 
2705
2717
 
2706
 
bool store_schema_shemata(THD* thd, Table *table, LEX_STRING *db_name,
 
2718
bool store_schema_shemata(Session* session, Table *table, LEX_STRING *db_name,
2707
2719
                          const CHARSET_INFO * const cs)
2708
2720
{
2709
2721
  restore_record(table, s->default_values);
2710
2722
  table->field[1]->store(db_name->str, db_name->length, system_charset_info);
2711
2723
  table->field[2]->store(cs->csname, strlen(cs->csname), system_charset_info);
2712
2724
  table->field[3]->store(cs->name, strlen(cs->name), system_charset_info);
2713
 
  return schema_table_store_record(thd, table);
 
2725
  return schema_table_store_record(session, table);
2714
2726
}
2715
2727
 
2716
2728
 
2717
 
int fill_schema_schemata(THD *thd, TableList *tables, COND *cond)
 
2729
int fill_schema_schemata(Session *session, TableList *tables, COND *cond)
2718
2730
{
2719
2731
  /*
2720
2732
    TODO: fill_schema_shemata() is called when new client is connected.
2728
2740
  HA_CREATE_INFO create;
2729
2741
  Table *table= tables->table;
2730
2742
 
2731
 
  if (get_lookup_field_values(thd, cond, tables, &lookup_field_vals))
 
2743
  if (get_lookup_field_values(session, cond, tables, &lookup_field_vals))
2732
2744
    return(0);
2733
 
  if (make_db_list(thd, &db_names, &lookup_field_vals,
 
2745
  if (make_db_list(session, &db_names, &lookup_field_vals,
2734
2746
                   &with_i_schema))
2735
2747
    return(1);
2736
2748
 
2757
2769
  {
2758
2770
    if (with_i_schema)       // information schema name is always first in list
2759
2771
    {
2760
 
      if (store_schema_shemata(thd, table, db_name,
 
2772
      if (store_schema_shemata(session, table, db_name,
2761
2773
                               system_charset_info))
2762
2774
        return(1);
2763
2775
      with_i_schema= 0;
2764
2776
      continue;
2765
2777
    }
2766
2778
    {
2767
 
      load_db_opt_by_name(thd, db_name->str, &create);
2768
 
      if (store_schema_shemata(thd, table, db_name,
 
2779
      load_db_opt_by_name(session, db_name->str, &create);
 
2780
      if (store_schema_shemata(session, table, db_name,
2769
2781
                               create.default_table_charset))
2770
2782
        return(1);
2771
2783
    }
2774
2786
}
2775
2787
 
2776
2788
 
2777
 
static int get_schema_tables_record(THD *thd, TableList *tables,
 
2789
static int get_schema_tables_record(Session *session, TableList *tables,
2778
2790
                                    Table *table, bool res,
2779
2791
                                    LEX_STRING *db_name,
2780
2792
                                    LEX_STRING *table_name)
2791
2803
    /*
2792
2804
      there was errors during opening tables
2793
2805
    */
2794
 
    const char *error= thd->is_error() ? thd->main_da.message() : "";
 
2806
    const char *error= session->is_error() ? session->main_da.message() : "";
2795
2807
    if (tables->schema_table)
2796
2808
      table->field[3]->store(STRING_WITH_LEN("SYSTEM VIEW"), cs);
2797
2809
    else
2798
2810
      table->field[3]->store(STRING_WITH_LEN("BASE Table"), cs);
2799
2811
    table->field[20]->store(error, strlen(error), cs);
2800
 
    thd->clear_error();
 
2812
    session->clear_error();
2801
2813
  }
2802
2814
  else
2803
2815
  {
2936
2948
      }
2937
2949
      if (file->stats.create_time)
2938
2950
      {
2939
 
        thd->variables.time_zone->gmt_sec_to_TIME(&time,
 
2951
        session->variables.time_zone->gmt_sec_to_TIME(&time,
2940
2952
                                                  (my_time_t) file->stats.create_time);
2941
2953
        table->field[14]->store_time(&time, DRIZZLE_TIMESTAMP_DATETIME);
2942
2954
        table->field[14]->set_notnull();
2943
2955
      }
2944
2956
      if (file->stats.update_time)
2945
2957
      {
2946
 
        thd->variables.time_zone->gmt_sec_to_TIME(&time,
 
2958
        session->variables.time_zone->gmt_sec_to_TIME(&time,
2947
2959
                                                  (my_time_t) file->stats.update_time);
2948
2960
        table->field[15]->store_time(&time, DRIZZLE_TIMESTAMP_DATETIME);
2949
2961
        table->field[15]->set_notnull();
2950
2962
      }
2951
2963
      if (file->stats.check_time)
2952
2964
      {
2953
 
        thd->variables.time_zone->gmt_sec_to_TIME(&time,
 
2965
        session->variables.time_zone->gmt_sec_to_TIME(&time,
2954
2966
                                                  (my_time_t) file->stats.check_time);
2955
2967
        table->field[16]->store_time(&time, DRIZZLE_TIMESTAMP_DATETIME);
2956
2968
        table->field[16]->set_notnull();
2962
2974
      }
2963
2975
    }
2964
2976
  }
2965
 
  return(schema_table_store_record(thd, table));
 
2977
  return(schema_table_store_record(session, table));
2966
2978
}
2967
2979
 
2968
2980
 
3024
3036
  case DRIZZLE_TYPE_NEWDECIMAL:
3025
3037
    field_length= ((Field_new_decimal*) field)->precision;
3026
3038
    break;
3027
 
  case DRIZZLE_TYPE_TINY:
3028
3039
  case DRIZZLE_TYPE_LONG:
3029
3040
  case DRIZZLE_TYPE_LONGLONG:
3030
3041
    field_length= field->max_display_length() - 1;
3065
3076
}
3066
3077
 
3067
3078
 
3068
 
static int get_schema_column_record(THD *thd, TableList *tables,
 
3079
static int get_schema_column_record(Session *session, TableList *tables,
3069
3080
                                    Table *table, bool res,
3070
3081
                                    LEX_STRING *db_name,
3071
3082
                                    LEX_STRING *table_name)
3072
3083
{
3073
 
  LEX *lex= thd->lex;
 
3084
  LEX *lex= session->lex;
3074
3085
  const char *wild= lex->wild ? lex->wild->ptr() : NULL;
3075
3086
  const CHARSET_INFO * const cs= system_charset_info;
3076
3087
  Table *show_table;
3086
3097
        I.e. we are in SELECT FROM INFORMATION_SCHEMA.COLUMS
3087
3098
        rather than in SHOW COLUMNS
3088
3099
      */ 
3089
 
      if (thd->is_error())
3090
 
        push_warning(thd, DRIZZLE_ERROR::WARN_LEVEL_WARN,
3091
 
                     thd->main_da.sql_errno(), thd->main_da.message());
3092
 
      thd->clear_error();
 
3100
      if (session->is_error())
 
3101
        push_warning(session, DRIZZLE_ERROR::WARN_LEVEL_WARN,
 
3102
                     session->main_da.sql_errno(), session->main_da.message());
 
3103
      session->clear_error();
3093
3104
      res= 0;
3094
3105
    }
3095
3106
    return(res);
3118
3129
      /* to satisfy 'field->val_str' ASSERTs */
3119
3130
      unsigned char *bitmaps;
3120
3131
      uint32_t bitmap_size= show_table_share->column_bitmap_size;
3121
 
      if (!(bitmaps= (unsigned char*) alloc_root(thd->mem_root, bitmap_size)))
 
3132
      if (!(bitmaps= (unsigned char*) alloc_root(session->mem_root, bitmap_size)))
3122
3133
        return(0);
3123
3134
      bitmap_init(&show_table->def_read_set,
3124
3135
                  (my_bitmap_map*) bitmaps, show_table_share->fields, false);
3137
3148
 
3138
3149
    /* to satisfy 'field->val_str' ASSERTs */
3139
3150
    field->table= show_table;
3140
 
    show_table->in_use= thd;
 
3151
    show_table->in_use= session;
3141
3152
 
3142
3153
    if (wild && wild[0] &&
3143
3154
        wild_case_compare(system_charset_info, field->field_name,wild))
3153
3164
                           cs);
3154
3165
    table->field[4]->store((int64_t) count, true);
3155
3166
 
3156
 
    if (get_field_default_value(thd, timestamp_field, field, &type, 0))
 
3167
    if (get_field_default_value(session, timestamp_field, field, &type, 0))
3157
3168
    {
3158
3169
      table->field[5]->store(type.ptr(), type.length(), cs);
3159
3170
      table->field[5]->set_notnull();
3176
3187
        field->unireg_check != Field::TIMESTAMP_DN_FIELD)
3177
3188
      table->field[16]->store(STRING_WITH_LEN("on update CURRENT_TIMESTAMP"),
3178
3189
                              cs);
3179
 
 
 
3190
    if (field->vcol_info)
 
3191
          table->field[16]->store(STRING_WITH_LEN("VIRTUAL"), cs);
3180
3192
    table->field[18]->store(field->comment.str, field->comment.length, cs);
3181
3193
    {
3182
3194
      enum column_format_type column_format= (enum column_format_type)
3190
3202
      table->field[20]->store((const char*) pos,
3191
3203
                              strlen((const char*) pos), cs);
3192
3204
    }
3193
 
    if (schema_table_store_record(thd, table))
 
3205
    if (schema_table_store_record(session, table))
3194
3206
      return(1);
3195
3207
  }
3196
3208
  return(0);
3198
3210
 
3199
3211
 
3200
3212
 
3201
 
int fill_schema_charsets(THD *thd, TableList *tables, COND *cond __attribute__((unused)))
 
3213
int fill_schema_charsets(Session *session, TableList *tables, COND *cond __attribute__((unused)))
3202
3214
{
3203
3215
  CHARSET_INFO **cs;
3204
 
  const char *wild= thd->lex->wild ? thd->lex->wild->ptr() : NULL;
 
3216
  const char *wild= session->lex->wild ? session->lex->wild->ptr() : NULL;
3205
3217
  Table *table= tables->table;
3206
3218
  const CHARSET_INFO * const scs= system_charset_info;
3207
3219
 
3221
3233
      comment= tmp_cs->comment ? tmp_cs->comment : "";
3222
3234
      table->field[2]->store(comment, strlen(comment), scs);
3223
3235
      table->field[3]->store((int64_t) tmp_cs->mbmaxlen, true);
3224
 
      if (schema_table_store_record(thd, table))
 
3236
      if (schema_table_store_record(session, table))
3225
3237
        return 1;
3226
3238
    }
3227
3239
  }
3229
3241
}
3230
3242
 
3231
3243
 
3232
 
int fill_schema_collation(THD *thd, TableList *tables, COND *cond __attribute__((unused)))
 
3244
int fill_schema_collation(Session *session, TableList *tables, COND *cond __attribute__((unused)))
3233
3245
{
3234
3246
  CHARSET_INFO **cs;
3235
 
  const char *wild= thd->lex->wild ? thd->lex->wild->ptr() : NULL;
 
3247
  const char *wild= session->lex->wild ? session->lex->wild->ptr() : NULL;
3236
3248
  Table *table= tables->table;
3237
3249
  const CHARSET_INFO * const scs= system_charset_info;
3238
3250
  for (cs= all_charsets ; cs < all_charsets+255 ; cs++ )
3262
3274
        tmp_buff= (tmp_cl->state & MY_CS_COMPILED)? "Yes" : "";
3263
3275
        table->field[4]->store(tmp_buff, strlen(tmp_buff), scs);
3264
3276
        table->field[5]->store((int64_t) tmp_cl->strxfrm_multiply, true);
3265
 
        if (schema_table_store_record(thd, table))
 
3277
        if (schema_table_store_record(session, table))
3266
3278
          return 1;
3267
3279
      }
3268
3280
    }
3271
3283
}
3272
3284
 
3273
3285
 
3274
 
int fill_schema_coll_charset_app(THD *thd, TableList *tables, COND *cond __attribute__((unused)))
 
3286
int fill_schema_coll_charset_app(Session *session, TableList *tables, COND *cond __attribute__((unused)))
3275
3287
{
3276
3288
  CHARSET_INFO **cs;
3277
3289
  Table *table= tables->table;
3292
3304
      restore_record(table, s->default_values);
3293
3305
      table->field[0]->store(tmp_cl->name, strlen(tmp_cl->name), scs);
3294
3306
      table->field[1]->store(tmp_cl->csname , strlen(tmp_cl->csname), scs);
3295
 
      if (schema_table_store_record(thd, table))
 
3307
      if (schema_table_store_record(session, table))
3296
3308
        return 1;
3297
3309
    }
3298
3310
  }
3300
3312
}
3301
3313
 
3302
3314
 
3303
 
static int get_schema_stat_record(THD *thd, TableList *tables,
 
3315
static int get_schema_stat_record(Session *session, TableList *tables,
3304
3316
                                  Table *table, bool res,
3305
3317
                                  LEX_STRING *db_name,
3306
3318
                                  LEX_STRING *table_name)
3308
3320
  const CHARSET_INFO * const cs= system_charset_info;
3309
3321
  if (res)
3310
3322
  {
3311
 
    if (thd->lex->sql_command != SQLCOM_SHOW_KEYS)
 
3323
    if (session->lex->sql_command != SQLCOM_SHOW_KEYS)
3312
3324
    {
3313
3325
      /*
3314
3326
        I.e. we are in SELECT FROM INFORMATION_SCHEMA.STATISTICS
3315
3327
        rather than in SHOW KEYS
3316
3328
      */
3317
 
      if (thd->is_error())
3318
 
        push_warning(thd, DRIZZLE_ERROR::WARN_LEVEL_WARN,
3319
 
                     thd->main_da.sql_errno(), thd->main_da.message());
3320
 
      thd->clear_error();
 
3329
      if (session->is_error())
 
3330
        push_warning(session, DRIZZLE_ERROR::WARN_LEVEL_WARN,
 
3331
                     session->main_da.sql_errno(), session->main_da.message());
 
3332
      session->clear_error();
3321
3333
      res= 0;
3322
3334
    }
3323
3335
    return(res);
3388
3400
        if (key_info->flags & HA_USES_COMMENT)
3389
3401
          table->field[15]->store(key_info->comment.str, 
3390
3402
                                  key_info->comment.length, cs);
3391
 
        if (schema_table_store_record(thd, table))
 
3403
        if (schema_table_store_record(session, table))
3392
3404
          return(1);
3393
3405
      }
3394
3406
    }
3397
3409
}
3398
3410
 
3399
3411
 
3400
 
bool store_constraints(THD *thd, Table *table, LEX_STRING *db_name,
 
3412
bool store_constraints(Session *session, Table *table, LEX_STRING *db_name,
3401
3413
                       LEX_STRING *table_name, const char *key_name,
3402
3414
                       uint32_t key_len, const char *con_type, uint32_t con_len)
3403
3415
{
3408
3420
  table->field[3]->store(db_name->str, db_name->length, cs);
3409
3421
  table->field[4]->store(table_name->str, table_name->length, cs);
3410
3422
  table->field[5]->store(con_type, con_len, cs);
3411
 
  return schema_table_store_record(thd, table);
 
3423
  return schema_table_store_record(session, table);
3412
3424
}
3413
3425
 
3414
3426
 
3415
 
static int get_schema_constraints_record(THD *thd, TableList *tables,
 
3427
static int get_schema_constraints_record(Session *session, TableList *tables,
3416
3428
                                         Table *table, bool res,
3417
3429
                                         LEX_STRING *db_name,
3418
3430
                                         LEX_STRING *table_name)
3419
3431
{
3420
3432
  if (res)
3421
3433
  {
3422
 
    if (thd->is_error())
3423
 
      push_warning(thd, DRIZZLE_ERROR::WARN_LEVEL_WARN,
3424
 
                   thd->main_da.sql_errno(), thd->main_da.message());
3425
 
    thd->clear_error();
 
3434
    if (session->is_error())
 
3435
      push_warning(session, DRIZZLE_ERROR::WARN_LEVEL_WARN,
 
3436
                   session->main_da.sql_errno(), session->main_da.message());
 
3437
    session->clear_error();
3426
3438
    return(0);
3427
3439
  }
3428
3440
  else
3441
3453
 
3442
3454
      if (i == primary_key && !strcmp(key_info->name, primary_key_name))
3443
3455
      {
3444
 
        if (store_constraints(thd, table, db_name, table_name, key_info->name,
 
3456
        if (store_constraints(session, table, db_name, table_name, key_info->name,
3445
3457
                              strlen(key_info->name),
3446
3458
                              STRING_WITH_LEN("PRIMARY KEY")))
3447
3459
          return(1);
3448
3460
      }
3449
3461
      else if (key_info->flags & HA_NOSAME)
3450
3462
      {
3451
 
        if (store_constraints(thd, table, db_name, table_name, key_info->name,
 
3463
        if (store_constraints(session, table, db_name, table_name, key_info->name,
3452
3464
                              strlen(key_info->name),
3453
3465
                              STRING_WITH_LEN("UNIQUE")))
3454
3466
          return(1);
3455
3467
      }
3456
3468
    }
3457
3469
 
3458
 
    show_table->file->get_foreign_key_list(thd, &f_key_list);
 
3470
    show_table->file->get_foreign_key_list(session, &f_key_list);
3459
3471
    FOREIGN_KEY_INFO *f_key_info;
3460
3472
    List_iterator_fast<FOREIGN_KEY_INFO> it(f_key_list);
3461
3473
    while ((f_key_info=it++))
3462
3474
    {
3463
 
      if (store_constraints(thd, table, db_name, table_name, 
 
3475
      if (store_constraints(session, table, db_name, table_name, 
3464
3476
                            f_key_info->forein_id->str,
3465
3477
                            strlen(f_key_info->forein_id->str),
3466
3478
                            "FOREIGN KEY", 11))
3486
3498
}
3487
3499
 
3488
3500
 
3489
 
static int get_schema_key_column_usage_record(THD *thd,
 
3501
static int get_schema_key_column_usage_record(Session *session,
3490
3502
                                              TableList *tables,
3491
3503
                                              Table *table, bool res,
3492
3504
                                              LEX_STRING *db_name,
3494
3506
{
3495
3507
  if (res)
3496
3508
  {
3497
 
    if (thd->is_error())
3498
 
      push_warning(thd, DRIZZLE_ERROR::WARN_LEVEL_WARN,
3499
 
                   thd->main_da.sql_errno(), thd->main_da.message());
3500
 
    thd->clear_error();
 
3509
    if (session->is_error())
 
3510
      push_warning(session, DRIZZLE_ERROR::WARN_LEVEL_WARN,
 
3511
                   session->main_da.sql_errno(), session->main_da.message());
 
3512
    session->clear_error();
3501
3513
    return(0);
3502
3514
  }
3503
3515
  else
3527
3539
                                 key_part->field->field_name, 
3528
3540
                                 strlen(key_part->field->field_name),
3529
3541
                                 (int64_t) f_idx);
3530
 
          if (schema_table_store_record(thd, table))
 
3542
          if (schema_table_store_record(session, table))
3531
3543
            return(1);
3532
3544
        }
3533
3545
      }
3534
3546
    }
3535
3547
 
3536
 
    show_table->file->get_foreign_key_list(thd, &f_key_list);
 
3548
    show_table->file->get_foreign_key_list(session, &f_key_list);
3537
3549
    FOREIGN_KEY_INFO *f_key_info;
3538
3550
    List_iterator_fast<FOREIGN_KEY_INFO> fkey_it(f_key_list);
3539
3551
    while ((f_key_info= fkey_it++))
3566
3578
        table->field[11]->store(r_info->str, r_info->length,
3567
3579
                                system_charset_info);
3568
3580
        table->field[11]->set_notnull();
3569
 
        if (schema_table_store_record(thd, table))
 
3581
        if (schema_table_store_record(session, table))
3570
3582
          return(1);
3571
3583
      }
3572
3584
    }
3575
3587
}
3576
3588
 
3577
3589
 
3578
 
int fill_open_tables(THD *thd, TableList *tables, COND *cond __attribute__((unused)))
 
3590
int fill_open_tables(Session *session, TableList *tables, COND *cond __attribute__((unused)))
3579
3591
{
3580
 
  const char *wild= thd->lex->wild ? thd->lex->wild->ptr() : NULL;
 
3592
  const char *wild= session->lex->wild ? session->lex->wild->ptr() : NULL;
3581
3593
  Table *table= tables->table;
3582
3594
  const CHARSET_INFO * const cs= system_charset_info;
3583
3595
  OPEN_TableList *open_list;
3584
 
  if (!(open_list=list_open_tables(thd,thd->lex->select_lex.db, wild))
3585
 
            && thd->is_fatal_error)
 
3596
  if (!(open_list=list_open_tables(session,session->lex->select_lex.db, wild))
 
3597
            && session->is_fatal_error)
3586
3598
    return(1);
3587
3599
 
3588
3600
  for (; open_list ; open_list=open_list->next)
3592
3604
    table->field[1]->store(open_list->table, strlen(open_list->table), cs);
3593
3605
    table->field[2]->store((int64_t) open_list->in_use, true);
3594
3606
    table->field[3]->store((int64_t) open_list->locked, true);
3595
 
    if (schema_table_store_record(thd, table))
 
3607
    if (schema_table_store_record(session, table))
3596
3608
      return(1);
3597
3609
  }
3598
3610
  return(0);
3599
3611
}
3600
3612
 
3601
3613
 
3602
 
int fill_variables(THD *thd, TableList *tables, COND *cond __attribute__((unused)))
 
3614
int fill_variables(Session *session, TableList *tables, COND *cond __attribute__((unused)))
3603
3615
{
3604
3616
  int res= 0;
3605
 
  LEX *lex= thd->lex;
 
3617
  LEX *lex= session->lex;
3606
3618
  const char *wild= lex->wild ? lex->wild->ptr() : NULL;
3607
3619
  enum enum_schema_tables schema_table_idx=
3608
3620
    get_schema_table_idx(tables->schema_table);
3615
3627
    option_type= OPT_GLOBAL;
3616
3628
 
3617
3629
  rw_rdlock(&LOCK_system_variables_hash);
3618
 
  res= show_status_array(thd, wild, enumerate_sys_vars(thd, sorted_vars),
 
3630
  res= show_status_array(session, wild, enumerate_sys_vars(session, sorted_vars),
3619
3631
                         option_type, NULL, "", tables->table, upper_case_names);
3620
3632
  rw_unlock(&LOCK_system_variables_hash);
3621
3633
  return(res);
3622
3634
}
3623
3635
 
3624
3636
 
3625
 
int fill_status(THD *thd, TableList *tables, COND *cond __attribute__((unused)))
 
3637
int fill_status(Session *session, TableList *tables, COND *cond __attribute__((unused)))
3626
3638
{
3627
 
  LEX *lex= thd->lex;
 
3639
  LEX *lex= session->lex;
3628
3640
  const char *wild= lex->wild ? lex->wild->ptr() : NULL;
3629
3641
  int res= 0;
3630
3642
  STATUS_VAR *tmp1, tmp;
3639
3651
    if (option_type == OPT_GLOBAL)
3640
3652
      tmp1= &tmp;
3641
3653
    else
3642
 
      tmp1= thd->initial_status_var;
 
3654
      tmp1= session->initial_status_var;
3643
3655
  }
3644
3656
  else if (schema_table_idx == SCH_GLOBAL_STATUS)
3645
3657
  {
3649
3661
  else
3650
3662
  { 
3651
3663
    option_type= OPT_SESSION;
3652
 
    tmp1= &thd->status_var;
 
3664
    tmp1= &session->status_var;
3653
3665
  }
3654
3666
 
3655
3667
  pthread_mutex_lock(&LOCK_status);
3656
3668
  if (option_type == OPT_GLOBAL)
3657
3669
    calc_sum_of_all_status(&tmp);
3658
 
  res= show_status_array(thd, wild,
 
3670
  res= show_status_array(session, wild,
3659
3671
                         (SHOW_VAR *)all_status_vars.buffer,
3660
3672
                         option_type, tmp1, "", tables->table,
3661
3673
                         upper_case_names);
3669
3681
 
3670
3682
  SYNOPSIS
3671
3683
    get_referential_constraints_record()
3672
 
    thd                 thread handle
 
3684
    session                 thread handle
3673
3685
    tables              table list struct(processed table)
3674
3686
    table               I_S table
3675
3687
    res                 1 means the error during opening of the processed table
3683
3695
*/
3684
3696
 
3685
3697
static int
3686
 
get_referential_constraints_record(THD *thd, TableList *tables,
 
3698
get_referential_constraints_record(Session *session, TableList *tables,
3687
3699
                                   Table *table, bool res,
3688
3700
                                   LEX_STRING *db_name, LEX_STRING *table_name)
3689
3701
{
3691
3703
 
3692
3704
  if (res)
3693
3705
  {
3694
 
    if (thd->is_error())
3695
 
      push_warning(thd, DRIZZLE_ERROR::WARN_LEVEL_WARN,
3696
 
                   thd->main_da.sql_errno(), thd->main_da.message());
3697
 
    thd->clear_error();
 
3706
    if (session->is_error())
 
3707
      push_warning(session, DRIZZLE_ERROR::WARN_LEVEL_WARN,
 
3708
                   session->main_da.sql_errno(), session->main_da.message());
 
3709
    session->clear_error();
3698
3710
    return(0);
3699
3711
  }
3700
3712
 
3705
3717
                           HA_STATUS_NO_LOCK |
3706
3718
                           HA_STATUS_TIME);
3707
3719
 
3708
 
    show_table->file->get_foreign_key_list(thd, &f_key_list);
 
3720
    show_table->file->get_foreign_key_list(session, &f_key_list);
3709
3721
    FOREIGN_KEY_INFO *f_key_info;
3710
3722
    List_iterator_fast<FOREIGN_KEY_INFO> it(f_key_list);
3711
3723
    while ((f_key_info= it++))
3732
3744
                             f_key_info->update_method->length, cs);
3733
3745
      table->field[8]->store(f_key_info->delete_method->str, 
3734
3746
                             f_key_info->delete_method->length, cs);
3735
 
      if (schema_table_store_record(thd, table))
 
3747
      if (schema_table_store_record(session, table))
3736
3748
        return(1);
3737
3749
    }
3738
3750
  }
3752
3764
 
3753
3765
  SYNOPSIS
3754
3766
    find_schema_table_in_plugin()
3755
 
    thd                 thread handler
 
3767
    session                 thread handler
3756
3768
    plugin              plugin
3757
3769
    table_name          table name
3758
3770
 
3760
3772
    0   table not found
3761
3773
    1   found the schema table
3762
3774
*/
3763
 
static bool find_schema_table_in_plugin(THD *thd __attribute__((unused)),
 
3775
static bool find_schema_table_in_plugin(Session *session __attribute__((unused)),
3764
3776
                                           plugin_ref plugin,
3765
3777
                                           void* p_table)
3766
3778
{
3784
3796
 
3785
3797
  SYNOPSIS
3786
3798
    find_schema_table()
3787
 
    thd                 thread handler
 
3799
    session                 thread handler
3788
3800
    table_name          table name
3789
3801
 
3790
3802
  RETURN
3792
3804
    #   pointer to 'schema_tables' element
3793
3805
*/
3794
3806
 
3795
 
ST_SCHEMA_TABLE *find_schema_table(THD *thd, const char* table_name)
 
3807
ST_SCHEMA_TABLE *find_schema_table(Session *session, const char* table_name)
3796
3808
{
3797
3809
  schema_table_ref schema_table_a;
3798
3810
  ST_SCHEMA_TABLE *schema_table= schema_tables;
3806
3818
  }
3807
3819
 
3808
3820
  schema_table_a.table_name= table_name;
3809
 
  if (plugin_foreach(thd, find_schema_table_in_plugin, 
 
3821
  if (plugin_foreach(session, find_schema_table_in_plugin, 
3810
3822
                     DRIZZLE_INFORMATION_SCHEMA_PLUGIN, &schema_table_a))
3811
3823
    return(schema_table_a.schema_table);
3812
3824
 
3826
3838
  @note
3827
3839
 
3828
3840
  @param
3829
 
    thd                   thread handler
 
3841
    session                       thread handler
3830
3842
 
3831
3843
  @param table_list Used to pass I_S table information(fields info, tables
3832
3844
  parameters etc) and table name.
3835
3847
  @retval  NULL           Can't create table
3836
3848
*/
3837
3849
 
3838
 
Table *create_schema_table(THD *thd, TableList *table_list)
 
3850
Table *create_schema_table(Session *session, TableList *table_list)
3839
3851
{
3840
3852
  int field_count= 0;
3841
3853
  Item *item;
3848
3860
  for (; fields_info->field_name; fields_info++)
3849
3861
  {
3850
3862
    switch (fields_info->field_type) {
3851
 
    case DRIZZLE_TYPE_TINY:
3852
3863
    case DRIZZLE_TYPE_LONG:
3853
3864
    case DRIZZLE_TYPE_LONGLONG:
3854
3865
      if (!(item= new Item_return_int(fields_info->field_name,
3911
3922
    field_count++;
3912
3923
  }
3913
3924
  TMP_TABLE_PARAM *tmp_table_param =
3914
 
    (TMP_TABLE_PARAM*) (thd->alloc(sizeof(TMP_TABLE_PARAM)));
 
3925
    (TMP_TABLE_PARAM*) (session->alloc(sizeof(TMP_TABLE_PARAM)));
3915
3926
  tmp_table_param->init();
3916
3927
  tmp_table_param->table_charset= cs;
3917
3928
  tmp_table_param->field_count= field_count;
3918
3929
  tmp_table_param->schema_table= 1;
3919
 
  SELECT_LEX *select_lex= thd->lex->current_select;
3920
 
  if (!(table= create_tmp_table(thd, tmp_table_param,
 
3930
  SELECT_LEX *select_lex= session->lex->current_select;
 
3931
  if (!(table= create_tmp_table(session, tmp_table_param,
3921
3932
                                field_list, (order_st*) 0, 0, 0, 
3922
 
                                (select_lex->options | thd->options |
 
3933
                                (select_lex->options | session->options |
3923
3934
                                 TMP_TABLE_ALL_COLUMNS),
3924
3935
                                HA_POS_ERROR, table_list->alias)))
3925
3936
    return(0);
3926
3937
  my_bitmap_map* bitmaps=
3927
 
    (my_bitmap_map*) thd->alloc(bitmap_buffer_size(field_count));
 
3938
    (my_bitmap_map*) session->alloc(bitmap_buffer_size(field_count));
3928
3939
  bitmap_init(&table->def_read_set, (my_bitmap_map*) bitmaps, field_count,
3929
3940
              false);
3930
3941
  table->read_set= &table->def_read_set;
3941
3952
 
3942
3953
  SYNOPSIS
3943
3954
    make_old_format()
3944
 
    thd                 thread handler
 
3955
    session                     thread handler
3945
3956
    schema_table        pointer to 'schema_tables' element
3946
3957
 
3947
3958
  RETURN
3949
3960
   0    success
3950
3961
*/
3951
3962
 
3952
 
int make_old_format(THD *thd, ST_SCHEMA_TABLE *schema_table)
 
3963
int make_old_format(Session *session, ST_SCHEMA_TABLE *schema_table)
3953
3964
{
3954
3965
  ST_FIELD_INFO *field_info= schema_table->fields_info;
3955
 
  Name_resolution_context *context= &thd->lex->select_lex.context;
 
3966
  Name_resolution_context *context= &session->lex->select_lex.context;
3956
3967
  for (; field_info->field_name; field_info++)
3957
3968
  {
3958
3969
    if (field_info->old_name)
3964
3975
        field->set_name(field_info->old_name,
3965
3976
                        strlen(field_info->old_name),
3966
3977
                        system_charset_info);
3967
 
        if (add_item_to_list(thd, field))
 
3978
        if (add_item_to_list(session, field))
3968
3979
          return 1;
3969
3980
      }
3970
3981
    }
3973
3984
}
3974
3985
 
3975
3986
 
3976
 
int make_schemata_old_format(THD *thd, ST_SCHEMA_TABLE *schema_table)
 
3987
int make_schemata_old_format(Session *session, ST_SCHEMA_TABLE *schema_table)
3977
3988
{
3978
3989
  char tmp[128];
3979
 
  LEX *lex= thd->lex;
 
3990
  LEX *lex= session->lex;
3980
3991
  SELECT_LEX *sel= lex->current_select;
3981
3992
  Name_resolution_context *context= &sel->context;
3982
3993
 
3986
3997
    String buffer(tmp,sizeof(tmp), system_charset_info);
3987
3998
    Item_field *field= new Item_field(context,
3988
3999
                                      NULL, NULL, field_info->field_name);
3989
 
    if (!field || add_item_to_list(thd, field))
 
4000
    if (!field || add_item_to_list(session, field))
3990
4001
      return 1;
3991
4002
    buffer.length(0);
3992
4003
    buffer.append(field_info->old_name);
4002
4013
}
4003
4014
 
4004
4015
 
4005
 
int make_table_names_old_format(THD *thd, ST_SCHEMA_TABLE *schema_table)
 
4016
int make_table_names_old_format(Session *session, ST_SCHEMA_TABLE *schema_table)
4006
4017
{
4007
4018
  char tmp[128];
4008
 
  String buffer(tmp,sizeof(tmp), thd->charset());
4009
 
  LEX *lex= thd->lex;
 
4019
  String buffer(tmp,sizeof(tmp), session->charset());
 
4020
  LEX *lex= session->lex;
4010
4021
  Name_resolution_context *context= &lex->select_lex.context;
4011
4022
 
4012
4023
  ST_FIELD_INFO *field_info= &schema_table->fields_info[2];
4021
4032
  }
4022
4033
  Item_field *field= new Item_field(context,
4023
4034
                                    NULL, NULL, field_info->field_name);
4024
 
  if (add_item_to_list(thd, field))
 
4035
  if (add_item_to_list(session, field))
4025
4036
    return 1;
4026
4037
  field->set_name(buffer.ptr(), buffer.length(), system_charset_info);
4027
 
  if (thd->lex->verbose)
 
4038
  if (session->lex->verbose)
4028
4039
  {
4029
4040
    field->set_name(buffer.ptr(), buffer.length(), system_charset_info);
4030
4041
    field_info= &schema_table->fields_info[3];
4031
4042
    field= new Item_field(context, NULL, NULL, field_info->field_name);
4032
 
    if (add_item_to_list(thd, field))
 
4043
    if (add_item_to_list(session, field))
4033
4044
      return 1;
4034
4045
    field->set_name(field_info->old_name, strlen(field_info->old_name),
4035
4046
                    system_charset_info);
4038
4049
}
4039
4050
 
4040
4051
 
4041
 
int make_columns_old_format(THD *thd, ST_SCHEMA_TABLE *schema_table)
 
4052
int make_columns_old_format(Session *session, ST_SCHEMA_TABLE *schema_table)
4042
4053
{
4043
4054
  int fields_arr[]= {3, 14, 13, 6, 15, 5, 16, 17, 18, -1};
4044
4055
  int *field_num= fields_arr;
4045
4056
  ST_FIELD_INFO *field_info;
4046
 
  Name_resolution_context *context= &thd->lex->select_lex.context;
 
4057
  Name_resolution_context *context= &session->lex->select_lex.context;
4047
4058
 
4048
4059
  for (; *field_num >= 0; field_num++)
4049
4060
  {
4050
4061
    field_info= &schema_table->fields_info[*field_num];
4051
 
    if (!thd->lex->verbose && (*field_num == 13 ||
 
4062
    if (!session->lex->verbose && (*field_num == 13 ||
4052
4063
                               *field_num == 17 ||
4053
4064
                               *field_num == 18))
4054
4065
      continue;
4059
4070
      field->set_name(field_info->old_name,
4060
4071
                      strlen(field_info->old_name),
4061
4072
                      system_charset_info);
4062
 
      if (add_item_to_list(thd, field))
 
4073
      if (add_item_to_list(session, field))
4063
4074
        return 1;
4064
4075
    }
4065
4076
  }
4067
4078
}
4068
4079
 
4069
4080
 
4070
 
int make_character_sets_old_format(THD *thd, ST_SCHEMA_TABLE *schema_table)
 
4081
int make_character_sets_old_format(Session *session, ST_SCHEMA_TABLE *schema_table)
4071
4082
{
4072
4083
  int fields_arr[]= {0, 2, 1, 3, -1};
4073
4084
  int *field_num= fields_arr;
4074
4085
  ST_FIELD_INFO *field_info;
4075
 
  Name_resolution_context *context= &thd->lex->select_lex.context;
 
4086
  Name_resolution_context *context= &session->lex->select_lex.context;
4076
4087
 
4077
4088
  for (; *field_num >= 0; field_num++)
4078
4089
  {
4084
4095
      field->set_name(field_info->old_name,
4085
4096
                      strlen(field_info->old_name),
4086
4097
                      system_charset_info);
4087
 
      if (add_item_to_list(thd, field))
 
4098
      if (add_item_to_list(session, field))
4088
4099
        return 1;
4089
4100
    }
4090
4101
  }
4097
4108
 
4098
4109
  SYNOPSIS
4099
4110
  mysql_schema_table()
4100
 
    thd                thread handler
 
4111
    session                thread handler
4101
4112
    lex                pointer to LEX
4102
4113
    table_list         pointer to table_list
4103
4114
 
4106
4117
    1   error
4107
4118
*/
4108
4119
 
4109
 
int mysql_schema_table(THD *thd, LEX *lex, TableList *table_list)
 
4120
int mysql_schema_table(Session *session, LEX *lex, TableList *table_list)
4110
4121
{
4111
4122
  Table *table;
4112
 
  if (!(table= table_list->schema_table->create_table(thd, table_list)))
 
4123
  if (!(table= table_list->schema_table->create_table(session, table_list)))
4113
4124
    return(1);
4114
4125
  table->s->tmp_table= SYSTEM_TMP_TABLE;
4115
4126
  /*
4126
4137
  table_list->table_name= table->s->table_name.str;
4127
4138
  table_list->table_name_length= table->s->table_name.length;
4128
4139
  table_list->table= table;
4129
 
  table->next= thd->derived_tables;
4130
 
  thd->derived_tables= table;
 
4140
  table->next= session->derived_tables;
 
4141
  session->derived_tables= table;
4131
4142
  table_list->select_lex->options |= OPTION_SCHEMA_TABLE;
4132
4143
 
4133
4144
  if (table_list->schema_table_reformed) // show command
4142
4153
      for (transl= table_list->field_translation; transl < end; transl++)
4143
4154
      {
4144
4155
        if (!transl->item->fixed &&
4145
 
            transl->item->fix_fields(thd, &transl->item))
 
4156
            transl->item->fix_fields(session, &transl->item))
4146
4157
          return(1);
4147
4158
      }
4148
4159
      return(0);
4149
4160
    }
4150
4161
    List_iterator_fast<Item> it(sel->item_list);
4151
4162
    if (!(transl=
4152
 
          (Field_translator*)(thd->alloc(sel->item_list.elements *
 
4163
          (Field_translator*)(session->alloc(sel->item_list.elements *
4153
4164
                                    sizeof(Field_translator)))))
4154
4165
    {
4155
4166
      return(1);
4158
4169
    {
4159
4170
      transl->item= item;
4160
4171
      transl->name= item->name;
4161
 
      if (!item->fixed && item->fix_fields(thd, &transl->item))
 
4172
      if (!item->fixed && item->fix_fields(session, &transl->item))
4162
4173
      {
4163
4174
        return(1);
4164
4175
      }
4176
4187
 
4177
4188
  SYNOPSIS
4178
4189
    make_schema_select()
4179
 
    thd                  thread handler
 
4190
    session                  thread handler
4180
4191
    sel                  pointer to SELECT_LEX
4181
4192
    schema_table_idx     index of 'schema_tables' element
4182
4193
 
4185
4196
    1   error
4186
4197
*/
4187
4198
 
4188
 
int make_schema_select(THD *thd, SELECT_LEX *sel,
 
4199
int make_schema_select(Session *session, SELECT_LEX *sel,
4189
4200
                       enum enum_schema_tables schema_table_idx)
4190
4201
{
4191
4202
  ST_SCHEMA_TABLE *schema_table= get_schema_table(schema_table_idx);
4194
4205
     We have to make non const db_name & table_name
4195
4206
     because of lower_case_table_names
4196
4207
  */
4197
 
  thd->make_lex_string(&db, INFORMATION_SCHEMA_NAME.str,
 
4208
  session->make_lex_string(&db, INFORMATION_SCHEMA_NAME.str,
4198
4209
                       INFORMATION_SCHEMA_NAME.length, 0);
4199
 
  thd->make_lex_string(&table, schema_table->table_name,
 
4210
  session->make_lex_string(&table, schema_table->table_name,
4200
4211
                       strlen(schema_table->table_name), 0);
4201
 
  if (schema_table->old_format(thd, schema_table) ||   /* Handle old syntax */
4202
 
      !sel->add_table_to_list(thd, new Table_ident(thd, db, table, 0),
 
4212
  if (schema_table->old_format(session, schema_table) ||   /* Handle old syntax */
 
4213
      !sel->add_table_to_list(session, new Table_ident(session, db, table, 0),
4203
4214
                              0, 0, TL_READ))
4204
4215
  {
4205
4216
    return(1);
4225
4236
                              enum enum_schema_table_state executed_place)
4226
4237
{
4227
4238
  JOIN_TAB *tmp_join_tab= join->join_tab+join->tables;
4228
 
  THD *thd= join->thd;
4229
 
  LEX *lex= thd->lex;
 
4239
  Session *session= join->session;
 
4240
  LEX *lex= session->lex;
4230
4241
  bool result= 0;
4231
4242
 
4232
 
  thd->no_warnings_for_error= 1;
 
4243
  session->no_warnings_for_error= 1;
4233
4244
  for (JOIN_TAB *tab= join->join_tab; tab < tmp_join_tab; tab++)
4234
4245
  {
4235
4246
    if (!tab->table || !tab->table->pos_in_table_list)
4243
4254
 
4244
4255
 
4245
4256
      /* skip I_S optimizations specific to get_all_tables */
4246
 
      if (thd->lex->describe &&
 
4257
      if (session->lex->describe &&
4247
4258
          (table_list->schema_table->fill_table != get_all_tables))
4248
4259
        continue;
4249
4260
 
4277
4288
      else
4278
4289
        table_list->table->file->stats.records= 0;
4279
4290
 
4280
 
      if (table_list->schema_table->fill_table(thd, table_list,
 
4291
      if (table_list->schema_table->fill_table(session, table_list,
4281
4292
                                               tab->select_cond))
4282
4293
      {
4283
4294
        result= 1;
4290
4301
      table_list->schema_table_state= executed_place;
4291
4302
    }
4292
4303
  }
4293
 
  thd->no_warnings_for_error= 0;
 
4304
  session->no_warnings_for_error= 0;
4294
4305
  return(result);
4295
4306
}
4296
4307