~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/sql_parse.cc

  • Committer: Monty Taylor
  • Date: 2008-10-16 06:32:30 UTC
  • mto: (511.1.5 codestyle)
  • mto: This revision was merged to the branch mainline in revision 521.
  • Revision ID: monty@inaugust.com-20081016063230-4brxsra0qsmsg84q
Added -Wunused-macros.

Show diffs side-by-side

added added

removed removed

Lines of Context:
13
13
   along with this program; if not, write to the Free Software
14
14
   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA */
15
15
 
16
 
#define MYSQL_LEX 1
17
 
#include "mysql_priv.h"
 
16
#define DRIZZLE_LEX 1
 
17
#include <drizzled/server_includes.h>
18
18
#include "sql_repl.h"
19
19
#include "rpl_filter.h"
20
 
#include "repl_failsafe.h"
21
 
#include <m_ctype.h>
22
 
#include <myisam.h>
23
 
#include <my_dir.h>
 
20
#include "logging.h"
 
21
#include <drizzled/drizzled_error_messages.h>
24
22
 
25
23
/**
26
24
  @defgroup Runtime_Environment Runtime Environment
27
25
  @{
28
26
*/
29
27
 
30
 
static bool execute_sqlcom_select(THD *thd, TABLE_LIST *all_tables);
31
28
 
32
29
const char *any_db="*any*";     // Special symbol for check_access
33
30
 
34
 
const LEX_STRING command_name[]={
 
31
const LEX_STRING command_name[COM_END+1]={
35
32
  { C_STRING_WITH_LEN("Sleep") },
36
33
  { C_STRING_WITH_LEN("Quit") },
37
34
  { C_STRING_WITH_LEN("Init DB") },
41
38
  { C_STRING_WITH_LEN("Drop DB") },
42
39
  { C_STRING_WITH_LEN("Refresh") },
43
40
  { C_STRING_WITH_LEN("Shutdown") },
44
 
  { C_STRING_WITH_LEN("Statistics") },
45
41
  { C_STRING_WITH_LEN("Processlist") },
46
42
  { C_STRING_WITH_LEN("Connect") },
47
43
  { C_STRING_WITH_LEN("Kill") },
48
 
  { C_STRING_WITH_LEN("Debug") },
49
44
  { C_STRING_WITH_LEN("Ping") },
50
45
  { C_STRING_WITH_LEN("Time") },
51
 
  { C_STRING_WITH_LEN("Delayed insert") },
52
46
  { C_STRING_WITH_LEN("Change user") },
53
47
  { C_STRING_WITH_LEN("Binlog Dump") },
54
 
  { C_STRING_WITH_LEN("Table Dump") },
55
48
  { C_STRING_WITH_LEN("Connect Out") },
56
49
  { C_STRING_WITH_LEN("Register Slave") },
57
 
  { C_STRING_WITH_LEN("Prepare") },
58
 
  { C_STRING_WITH_LEN("Execute") },
59
 
  { C_STRING_WITH_LEN("Long Data") },
60
 
  { C_STRING_WITH_LEN("Close stmt") },
61
 
  { C_STRING_WITH_LEN("Reset stmt") },
62
50
  { C_STRING_WITH_LEN("Set option") },
63
 
  { C_STRING_WITH_LEN("Fetch") },
64
51
  { C_STRING_WITH_LEN("Daemon") },
65
52
  { C_STRING_WITH_LEN("Error") }  // Last command number
66
53
};
82
69
 
83
70
bool end_active_trans(THD *thd)
84
71
{
85
 
  int error=0;
86
 
  if (unlikely(thd->in_sub_stmt))
87
 
  {
88
 
    my_error(ER_COMMIT_NOT_ALLOWED_IN_SF_OR_TRG, MYF(0));
89
 
    return(1);
90
 
  }
 
72
  int error= 0;
 
73
 
91
74
  if (thd->transaction.xid_state.xa_state != XA_NOTR)
92
75
  {
93
76
    my_error(ER_XAER_RMFAIL, MYF(0),
112
95
 
113
96
bool begin_trans(THD *thd)
114
97
{
115
 
  int error=0;
116
 
  if (unlikely(thd->in_sub_stmt))
117
 
  {
118
 
    my_error(ER_COMMIT_NOT_ALLOWED_IN_SF_OR_TRG, MYF(0));
119
 
    return 1;
120
 
  }
 
98
  int error= 0;
121
99
  if (thd->locked_tables)
122
100
  {
123
101
    thd->lock=thd->locked_tables;
131
109
    LEX *lex= thd->lex;
132
110
    thd->options|= OPTION_BEGIN;
133
111
    thd->server_status|= SERVER_STATUS_IN_TRANS;
134
 
    if (lex->start_transaction_opt & MYSQL_START_TRANS_OPT_WITH_CONS_SNAPSHOT)
 
112
    if (lex->start_transaction_opt & DRIZZLE_START_TRANS_OPT_WITH_CONS_SNAPSHOT)
135
113
      error= ha_start_consistent_snapshot(thd);
136
114
  }
137
115
  return error;
140
118
/**
141
119
  Returns true if all tables should be ignored.
142
120
*/
143
 
inline bool all_tables_not_ok(THD *thd, TABLE_LIST *tables)
 
121
inline bool all_tables_not_ok(THD *thd, TableList *tables)
144
122
{
145
123
  return rpl_filter->is_on() && tables &&
146
124
         !rpl_filter->tables_ok(thd->db, tables);
147
125
}
148
126
 
149
127
 
150
 
static bool some_non_temp_table_to_be_updated(THD *thd, TABLE_LIST *tables)
 
128
static bool some_non_temp_table_to_be_updated(THD *thd, TableList *tables)
151
129
{
152
 
  for (TABLE_LIST *table= tables; table; table= table->next_global)
 
130
  for (TableList *table= tables; table; table= table->next_global)
153
131
  {
154
132
    assert(table->db && table->table_name);
155
133
    if (table->updating &&
173
151
          a number of modified rows
174
152
*/
175
153
 
176
 
uint sql_command_flags[SQLCOM_END+1];
 
154
uint32_t sql_command_flags[SQLCOM_END+1];
177
155
 
178
156
void init_update_queries(void)
179
157
{
180
 
  bzero((uchar*) &sql_command_flags, sizeof(sql_command_flags));
 
158
  memset(&sql_command_flags, 0, sizeof(sql_command_flags));
181
159
 
182
160
  sql_command_flags[SQLCOM_CREATE_TABLE]=   CF_CHANGES_DATA;
183
161
  sql_command_flags[SQLCOM_CREATE_INDEX]=   CF_CHANGES_DATA;
205
183
  sql_command_flags[SQLCOM_SHOW_FIELDS]=      CF_STATUS_COMMAND;
206
184
  sql_command_flags[SQLCOM_SHOW_KEYS]=        CF_STATUS_COMMAND;
207
185
  sql_command_flags[SQLCOM_SHOW_VARIABLES]=   CF_STATUS_COMMAND;
208
 
  sql_command_flags[SQLCOM_SHOW_CHARSETS]=    CF_STATUS_COMMAND;
209
 
  sql_command_flags[SQLCOM_SHOW_COLLATIONS]=  CF_STATUS_COMMAND;
210
186
  sql_command_flags[SQLCOM_SHOW_BINLOGS]= CF_STATUS_COMMAND;
211
 
  sql_command_flags[SQLCOM_SHOW_SLAVE_HOSTS]= CF_STATUS_COMMAND;
212
 
  sql_command_flags[SQLCOM_SHOW_BINLOG_EVENTS]= CF_STATUS_COMMAND;
213
187
  sql_command_flags[SQLCOM_SHOW_WARNS]= CF_STATUS_COMMAND;
214
188
  sql_command_flags[SQLCOM_SHOW_ERRORS]= CF_STATUS_COMMAND;
215
189
  sql_command_flags[SQLCOM_SHOW_ENGINE_STATUS]= CF_STATUS_COMMAND;
245
219
  Vio* save_vio;
246
220
  ulong save_client_capabilities;
247
221
 
248
 
  thd_proc_info(thd, "Execution of init_command");
 
222
  thd->set_proc_info("Execution of init_command");
249
223
  /*
250
224
    We need to lock init_command_var because
251
225
    during execution of init_command_var query
253
227
  */
254
228
  rw_rdlock(var_mutex);
255
229
  save_client_capabilities= thd->client_capabilities;
256
 
  thd->client_capabilities|= CLIENT_MULTI_QUERIES;
 
230
  thd->client_capabilities|= CLIENT_MULTI_STATEMENTS;
257
231
  /*
258
232
    We don't need return result of execution to client side.
259
233
    To forbid this we should set thd->net.vio to 0.
283
257
  bool do_release= 0;
284
258
  int res= 0;
285
259
 
286
 
  if (unlikely(thd->in_sub_stmt))
287
 
  {
288
 
    my_error(ER_COMMIT_NOT_ALLOWED_IN_SF_OR_TRG, MYF(0));
289
 
    return(1);
290
 
  }
291
260
  if (thd->transaction.xid_state.xa_state != XA_NOTR)
292
261
  {
293
262
    my_error(ER_XAER_RMFAIL, MYF(0),
417
386
  if (packet_length == 0)                       /* safety */
418
387
  {
419
388
    /* Initialize with COM_SLEEP packet */
420
 
    packet[0]= (uchar) COM_SLEEP;
 
389
    packet[0]= (unsigned char) COM_SLEEP;
421
390
    packet_length= 1;
422
391
  }
423
392
  /* Do not rely on my_net_read, extra safety against programming errors. */
424
393
  packet[packet_length]= '\0';                  /* safety */
425
394
 
426
 
  command= (enum enum_server_command) (uchar) packet[0];
 
395
  command= (enum enum_server_command) (unsigned char) packet[0];
427
396
 
428
397
  if (command >= COM_END)
429
398
    command= COM_END;                           // Wrong command
432
401
  my_net_set_read_timeout(net, thd->variables.net_read_timeout);
433
402
 
434
403
  assert(packet_length);
435
 
  return_value= dispatch_command(command, thd, packet+1, (uint) (packet_length-1));
 
404
  return_value= dispatch_command(command, thd, packet+1, (uint32_t) (packet_length-1));
436
405
 
437
406
out:
438
407
  return(return_value);
453
422
    @retval false The statement isn't updating any relevant tables.
454
423
*/
455
424
 
456
 
static my_bool deny_updates_if_read_only_option(THD *thd,
457
 
                                                TABLE_LIST *all_tables)
 
425
static bool deny_updates_if_read_only_option(THD *thd,
 
426
                                                TableList *all_tables)
458
427
{
459
428
  if (!opt_readonly)
460
429
    return(false);
468
437
  if (lex->sql_command == SQLCOM_UPDATE_MULTI)
469
438
    return(false);
470
439
 
471
 
  const my_bool create_temp_tables= 
 
440
  const bool create_temp_tables= 
472
441
    (lex->sql_command == SQLCOM_CREATE_TABLE) &&
473
442
    (lex->create_info.options & HA_LEX_CREATE_TMP_TABLE);
474
443
 
475
 
  const my_bool drop_temp_tables= 
 
444
  const bool drop_temp_tables= 
476
445
    (lex->sql_command == SQLCOM_DROP_TABLE) &&
477
446
    lex->drop_temporary;
478
447
 
479
 
  const my_bool update_real_tables=
 
448
  const bool update_real_tables=
480
449
    some_non_temp_table_to_be_updated(thd, all_tables) &&
481
450
    !(create_temp_tables || drop_temp_tables);
482
451
 
483
452
 
484
 
  const my_bool create_or_drop_databases=
 
453
  const bool create_or_drop_databases=
485
454
    (lex->sql_command == SQLCOM_CREATE_DB) ||
486
455
    (lex->sql_command == SQLCOM_DROP_DB);
487
456
 
520
489
        COM_QUIT/COM_SHUTDOWN
521
490
*/
522
491
bool dispatch_command(enum enum_server_command command, THD *thd,
523
 
                      char* packet, uint packet_length)
 
492
                      char* packet, uint32_t packet_length)
524
493
{
525
494
  NET *net= &thd->net;
526
495
  bool error= 0;
527
496
 
528
497
  thd->command=command;
529
 
  /*
530
 
    Commands which always take a long time are logged into
531
 
    the slow log only if opt_log_slow_admin_statements is set.
532
 
  */
533
 
  thd->enable_slow_log= true;
534
498
  thd->lex->sql_command= SQLCOM_END; /* to avoid confusing VIEW detectors */
535
499
  thd->set_time();
536
 
  VOID(pthread_mutex_lock(&LOCK_thread_count));
 
500
  pthread_mutex_lock(&LOCK_thread_count);
537
501
  thd->query_id= global_query_id;
538
502
 
539
503
  switch( command ) {
540
504
  /* Ignore these statements. */
541
 
  case COM_STATISTICS:
542
505
  case COM_PING:
543
506
    break;
544
 
  /* Only increase id on these statements but don't count them. */
545
 
  case COM_STMT_PREPARE: 
546
 
  case COM_STMT_CLOSE:
547
 
  case COM_STMT_RESET:
548
 
    next_query_id();
549
 
    break;
550
507
  /* Increase id and count all other statements. */
551
508
  default:
552
509
    statistic_increment(thd->status_var.questions, &LOCK_status);
555
512
 
556
513
  thread_running++;
557
514
  /* TODO: set thd->lex->sql_command to SQLCOM_END here */
558
 
  VOID(pthread_mutex_unlock(&LOCK_thread_count));
 
515
  pthread_mutex_unlock(&LOCK_thread_count);
 
516
 
 
517
  logging_pre_do(thd);
559
518
 
560
519
  thd->server_status&=
561
520
           ~(SERVER_QUERY_NO_INDEX_USED | SERVER_QUERY_NO_GOOD_INDEX_USED);
568
527
                        packet, packet_length, thd->charset());
569
528
    if (!mysql_change_db(thd, &tmp, false))
570
529
    {
571
 
      general_log_write(thd, command, thd->db, thd->db_length);
572
530
      my_ok(thd);
573
531
    }
574
532
    break;
575
533
  }
576
 
  case COM_REGISTER_SLAVE:
577
 
  {
578
 
    if (!register_slave(thd, (uchar*)packet, packet_length))
579
 
      my_ok(thd);
580
 
    break;
581
 
  }
582
534
  case COM_CHANGE_USER:
583
535
  {
584
536
    status_var_increment(thd->status_var.com_other);
585
537
    char *user= (char*) packet, *packet_end= packet + packet_length;
586
538
    /* Safe because there is always a trailing \0 at the end of the packet */
587
 
    char *passwd= strend(user)+1;
 
539
    char *passwd= strchr(user, '\0')+1;
 
540
 
588
541
 
589
542
    thd->clear_error();                         // if errors from rollback
590
543
 
594
547
      terminated, so also '\0' for empty string).
595
548
 
596
549
      Cast *passwd to an unsigned char, so that it doesn't extend the sign
597
 
      for *passwd > 127 and become 2**32-127 after casting to uint.
 
550
      for *passwd > 127 and become 2**32-127 after casting to uint32_t.
598
551
    */
599
552
    char db_buff[NAME_LEN+1];                 // buffer to store db in utf8
600
553
    char *db= passwd;
608
561
      my_message(ER_UNKNOWN_COM_ERROR, ER(ER_UNKNOWN_COM_ERROR), MYF(0));
609
562
      break;
610
563
    }
611
 
    uint passwd_len= (thd->client_capabilities & CLIENT_SECURE_CONNECTION ?
612
 
                      (uchar)(*passwd++) : strlen(passwd));
613
 
    uint dummy_errors, save_db_length, db_length;
 
564
    uint32_t passwd_len= (thd->client_capabilities & CLIENT_SECURE_CONNECTION ?
 
565
                      (unsigned char)(*passwd++) : strlen(passwd));
 
566
    uint32_t dummy_errors, save_db_length, db_length;
614
567
    int res;
615
568
    Security_context save_security_ctx= *thd->security_ctx;
616
569
    USER_CONN *save_user_connect;
628
581
    db_length= strlen(db);
629
582
 
630
583
    char *ptr= db + db_length + 1;
631
 
    uint cs_number= 0;
 
584
    uint32_t cs_number= 0;
632
585
 
633
586
    if (ptr < packet_end)
634
587
    {
661
614
 
662
615
    /* Clear variables that are allocated */
663
616
    thd->user_connect= 0;
664
 
    thd->security_ctx->priv_user= thd->security_ctx->user;
665
 
    res= check_user(thd, COM_CHANGE_USER, passwd, passwd_len, db, false);
 
617
    res= check_user(thd, passwd, passwd_len, db, false);
666
618
 
667
619
    if (res)
668
620
    {
669
 
      x_free(thd->security_ctx->user);
 
621
      if (thd->security_ctx->user)
 
622
        free(thd->security_ctx->user);
670
623
      *thd->security_ctx= save_security_ctx;
671
624
      thd->user_connect= save_user_connect;
672
625
      thd->db= save_db;
674
627
    }
675
628
    else
676
629
    {
677
 
      x_free(save_db);
678
 
      x_free(save_security_ctx.user);
 
630
      if (save_db)
 
631
        free(save_db);
 
632
      if (save_security_ctx.user)
 
633
        free(save_security_ctx.user);
679
634
 
680
635
      if (cs_number)
681
636
      {
685
640
    }
686
641
    break;
687
642
  }
688
 
  case COM_STMT_EXECUTE:
689
 
  case COM_STMT_FETCH:
690
 
  case COM_STMT_SEND_LONG_DATA:
691
 
  case COM_STMT_PREPARE:
692
 
  case COM_STMT_CLOSE:
693
 
  case COM_STMT_RESET:
694
 
  {
695
 
    /* We should toss an error here */
696
 
    break;
697
 
  }
698
643
  case COM_QUERY:
699
644
  {
700
645
    if (alloc_query(thd, packet, packet_length))
702
647
    char *packet_end= thd->query + thd->query_length;
703
648
    const char* end_of_stmt= NULL;
704
649
 
705
 
    general_log_write(thd, command, thd->query, thd->query_length);
706
 
 
707
650
    mysql_parse(thd, thd->query, thd->query_length, &end_of_stmt);
708
651
 
709
652
    while (!thd->killed && (end_of_stmt != NULL) && ! thd->is_error())
726
669
        length--;
727
670
      }
728
671
 
729
 
      VOID(pthread_mutex_lock(&LOCK_thread_count));
 
672
      pthread_mutex_lock(&LOCK_thread_count);
730
673
      thd->query_length= length;
731
674
      thd->query= beginning_of_next_stmt;
732
675
      /*
736
679
      thd->query_id= next_query_id();
737
680
      thd->set_time(); /* Reset the query start time. */
738
681
      /* TODO: set thd->lex->sql_command to SQLCOM_END here */
739
 
      VOID(pthread_mutex_unlock(&LOCK_thread_count));
 
682
      pthread_mutex_unlock(&LOCK_thread_count);
740
683
 
741
684
      mysql_parse(thd, beginning_of_next_stmt, length, &end_of_stmt);
742
685
    }
746
689
  {
747
690
    char *fields, *packet_end= packet + packet_length, *arg_end;
748
691
    /* Locked closure of all tables */
749
 
    TABLE_LIST table_list;
 
692
    TableList table_list;
750
693
    LEX_STRING conv_name;
751
694
 
752
695
    /* used as fields initializator */
753
696
    lex_start(thd);
754
697
 
755
698
    status_var_increment(thd->status_var.com_stat[SQLCOM_SHOW_FIELDS]);
756
 
    bzero((char*) &table_list,sizeof(table_list));
 
699
    memset(&table_list, 0, sizeof(table_list));
757
700
    if (thd->copy_db_to(&table_list.db, &table_list.db_length))
758
701
      break;
759
702
    /*
760
703
      We have name + wildcard in packet, separated by endzero
761
704
    */
762
 
    arg_end= strend(packet);
 
705
    arg_end= strchr(packet, '\0');
763
706
    thd->convert_string(&conv_name, system_charset_info,
764
 
                        packet, (uint) (arg_end - packet), thd->charset());
 
707
                        packet, (uint32_t) (arg_end - packet), thd->charset());
765
708
    table_list.alias= table_list.table_name= conv_name.str;
766
709
    packet= arg_end + 1;
767
710
 
773
716
        table_list.schema_table= schema_table;
774
717
    }
775
718
 
776
 
    thd->query_length= (uint) (packet_end - packet); // Don't count end \0
 
719
    thd->query_length= (uint32_t) (packet_end - packet); // Don't count end \0
777
720
    if (!(thd->query=fields= (char*) thd->memdup(packet,thd->query_length+1)))
778
721
      break;
779
 
    general_log_print(thd, command, "%s %s", table_list.table_name, fields);
780
722
    if (lower_case_table_names)
781
723
      my_casedn_str(files_charset_info, table_list.table_name);
782
724
 
787
729
    mysql_reset_thd_for_next_command(thd);
788
730
 
789
731
    thd->lex->
790
 
      select_lex.table_list.link_in_list((uchar*) &table_list,
791
 
                                         (uchar**) &table_list.next_local);
 
732
      select_lex.table_list.link_in_list((unsigned char*) &table_list,
 
733
                                         (unsigned char**) &table_list.next_local);
792
734
    thd->lex->add_to_query_tables(&table_list);
793
735
 
794
736
    /* switch on VIEW optimisation: do not fill temporary tables */
800
742
  }
801
743
  case COM_QUIT:
802
744
    /* We don't calculate statistics for this command */
803
 
    general_log_print(thd, command, NullS);
804
745
    net->error=0;                               // Don't give 'abort' message
805
746
    thd->main_da.disable_status();              // Don't send anything back
806
747
    error=true;                                 // End server
808
749
  case COM_BINLOG_DUMP:
809
750
    {
810
751
      ulong pos;
811
 
      ushort flags;
812
 
      uint32 slave_server_id;
 
752
      uint16_t flags;
 
753
      uint32_t slave_server_id;
813
754
 
814
755
      status_var_increment(thd->status_var.com_other);
815
 
      thd->enable_slow_log= opt_log_slow_admin_statements;
816
756
      /* TODO: The following has to be changed to an 8 byte integer */
817
757
      pos = uint4korr(packet);
818
758
      flags = uint2korr(packet + 4);
821
761
        kill_zombie_dump_threads(slave_server_id);
822
762
      thd->server_id = slave_server_id;
823
763
 
824
 
      general_log_print(thd, command, "Log: '%s'  Pos: %ld", packet+10,
825
 
                      (long) pos);
826
764
      mysql_binlog_send(thd, thd->strdup(packet + 10), (my_off_t) pos, flags);
827
 
      unregister_slave(thd,1,1);
828
765
      /*  fake COM_QUIT -- if we get here, the thread needs to terminate */
829
766
      error = true;
830
767
      break;
832
769
  case COM_SHUTDOWN:
833
770
  {
834
771
    status_var_increment(thd->status_var.com_other);
835
 
    /*
836
 
      If the client is < 4.1.3, it is going to send us no argument; then
837
 
      packet_length is 0, packet[0] is the end 0 of the packet. Note that
838
 
      SHUTDOWN_DEFAULT is 0. If client is >= 4.1.3, the shutdown level is in
839
 
      packet[0].
840
 
    */
841
 
    enum mysql_enum_shutdown_level level=
842
 
      (enum mysql_enum_shutdown_level) (uchar) packet[0];
843
 
    if (level == SHUTDOWN_DEFAULT)
844
 
      level= SHUTDOWN_WAIT_ALL_BUFFERS; // soon default will be configurable
845
 
    else if (level != SHUTDOWN_WAIT_ALL_BUFFERS)
846
 
    {
847
 
      my_error(ER_NOT_SUPPORTED_YET, MYF(0), "this shutdown level");
848
 
      break;
849
 
    }
850
 
    general_log_print(thd, command, NullS);
851
772
    my_eof(thd);
852
773
    close_thread_tables(thd);                   // Free before kill
853
774
    kill_mysql();
854
775
    error=true;
855
776
    break;
856
777
  }
857
 
  case COM_STATISTICS:
858
 
  {
859
 
    STATUS_VAR current_global_status_var;
860
 
    ulong uptime;
861
 
    uint length;
862
 
    uint64_t queries_per_second1000;
863
 
    char buff[250];
864
 
    uint buff_len= sizeof(buff);
865
 
 
866
 
    general_log_print(thd, command, NullS);
867
 
    status_var_increment(thd->status_var.com_stat[SQLCOM_SHOW_STATUS]);
868
 
    calc_sum_of_all_status(&current_global_status_var);
869
 
    if (!(uptime= (ulong) (thd->start_time - server_start_time)))
870
 
      queries_per_second1000= 0;
871
 
    else
872
 
      queries_per_second1000= thd->query_id * 1000LL / uptime;
873
 
 
874
 
    length= snprintf((char*) buff, buff_len - 1,
875
 
                     "Uptime: %lu  Threads: %d  Questions: %lu  "
876
 
                     "Slow queries: %lu  Opens: %lu  Flush tables: %lu  "
877
 
                     "Open tables: %u  Queries per second avg: %u.%u",
878
 
                     uptime,
879
 
                     (int) thread_count, (ulong) thd->query_id,
880
 
                     current_global_status_var.long_query_count,
881
 
                     current_global_status_var.opened_tables,
882
 
                     refresh_version,
883
 
                     cached_open_tables(),
884
 
                     (uint) (queries_per_second1000 / 1000),
885
 
                     (uint) (queries_per_second1000 % 1000));
886
 
    /* Store the buffer in permanent memory */
887
 
    my_ok(thd, 0, 0, buff);
888
 
    VOID(my_net_write(net, (uchar*) buff, length));
889
 
    VOID(net_flush(net));
890
 
    thd->main_da.disable_status();
891
 
    break;
892
 
  }
893
778
  case COM_PING:
894
779
    status_var_increment(thd->status_var.com_other);
895
780
    my_ok(thd);                         // Tell client we are alive
896
781
    break;
897
782
  case COM_PROCESS_INFO:
898
783
    status_var_increment(thd->status_var.com_stat[SQLCOM_SHOW_PROCESSLIST]);
899
 
    general_log_print(thd, command, NullS);
900
 
    mysqld_list_processes(thd, NullS, 0);
 
784
    mysqld_list_processes(thd, NULL, 0);
901
785
    break;
902
786
  case COM_PROCESS_KILL:
903
787
  {
909
793
  case COM_SET_OPTION:
910
794
  {
911
795
    status_var_increment(thd->status_var.com_stat[SQLCOM_SET_OPTION]);
912
 
    uint opt_command= uint2korr(packet);
 
796
    uint32_t opt_command= uint2korr(packet);
913
797
 
914
798
    switch (opt_command) {
915
 
    case (int) MYSQL_OPTION_MULTI_STATEMENTS_ON:
 
799
    case (int) DRIZZLE_OPTION_MULTI_STATEMENTS_ON:
916
800
      thd->client_capabilities|= CLIENT_MULTI_STATEMENTS;
917
801
      my_eof(thd);
918
802
      break;
919
 
    case (int) MYSQL_OPTION_MULTI_STATEMENTS_OFF:
 
803
    case (int) DRIZZLE_OPTION_MULTI_STATEMENTS_OFF:
920
804
      thd->client_capabilities&= ~CLIENT_MULTI_STATEMENTS;
921
805
      my_eof(thd);
922
806
      break;
957
841
 
958
842
  net_end_statement(thd);
959
843
 
960
 
  thd->proc_info= "closing tables";
 
844
  thd->set_proc_info("closing tables");
961
845
  /* Free tables */
962
846
  close_thread_tables(thd);
963
847
 
964
848
  log_slow_statement(thd);
965
849
 
966
 
  thd_proc_info(thd, "cleaning up");
967
 
  VOID(pthread_mutex_lock(&LOCK_thread_count)); // For process list
968
 
  thd_proc_info(thd, 0);
 
850
  thd->set_proc_info("cleaning up");
 
851
  pthread_mutex_lock(&LOCK_thread_count); // For process list
 
852
  thd->set_proc_info(0);
969
853
  thd->command=COM_SLEEP;
970
854
  thd->query=0;
971
855
  thd->query_length=0;
972
856
  thread_running--;
973
 
  VOID(pthread_mutex_unlock(&LOCK_thread_count));
 
857
  pthread_mutex_unlock(&LOCK_thread_count);
974
858
  thd->packet.shrink(thd->variables.net_buffer_length); // Reclaim some memory
975
859
  free_root(thd->mem_root,MYF(MY_KEEP_PREALLOC));
976
860
  return(error);
979
863
 
980
864
void log_slow_statement(THD *thd)
981
865
{
982
 
  /*
983
 
    The following should never be true with our current code base,
984
 
    but better to keep this here so we don't accidently try to log a
985
 
    statement in a trigger or stored function
986
 
  */
987
 
  if (unlikely(thd->in_sub_stmt))
988
 
    return;                           // Don't set time for sub stmt
989
 
 
990
 
  /*
991
 
    Do not log administrative statements unless the appropriate option is
992
 
    set; do not log into slow log if reading from backup.
993
 
  */
994
 
  if (thd->enable_slow_log && !thd->user_time)
995
 
  {
996
 
    thd_proc_info(thd, "logging slow query");
997
 
    uint64_t end_utime_of_query= thd->current_utime();
998
 
 
999
 
    if (((end_utime_of_query - thd->utime_after_lock) >
1000
 
         thd->variables.long_query_time ||
1001
 
         ((thd->server_status &
1002
 
           (SERVER_QUERY_NO_INDEX_USED | SERVER_QUERY_NO_GOOD_INDEX_USED)) &&
1003
 
          opt_log_queries_not_using_indexes &&
1004
 
           !(sql_command_flags[thd->lex->sql_command] & CF_STATUS_COMMAND))) &&
1005
 
        thd->examined_row_count >= thd->variables.min_examined_row_limit)
1006
 
    {
1007
 
      thd_proc_info(thd, "logging slow query");
1008
 
      thd->status_var.long_query_count++;
1009
 
      slow_log_print(thd, thd->query, thd->query_length, end_utime_of_query);
1010
 
    }
1011
 
  }
 
866
  logging_post_do(thd);
 
867
 
1012
868
  return;
1013
869
}
1014
870
 
1015
871
 
1016
872
/**
1017
 
  Create a TABLE_LIST object for an INFORMATION_SCHEMA table.
 
873
  Create a TableList object for an INFORMATION_SCHEMA table.
1018
874
 
1019
875
    This function is used in the parser to convert a SHOW or DESCRIBE
1020
876
    table_name command to a SELECT from INFORMATION_SCHEMA.
1021
 
    It prepares a SELECT_LEX and a TABLE_LIST object to represent the
 
877
    It prepares a SELECT_LEX and a TableList object to represent the
1022
878
    given command as a SELECT parse tree.
1023
879
 
1024
880
  @param thd              thread handle
1073
929
  case SCH_STATISTICS:
1074
930
  {
1075
931
    assert(table_ident);
1076
 
    TABLE_LIST **query_tables_last= lex->query_tables_last;
 
932
    TableList **query_tables_last= lex->query_tables_last;
1077
933
    schema_select_lex= new SELECT_LEX();
1078
934
    /* 'parent_lex' is used in init_query() so it must be before it. */
1079
935
    schema_select_lex->parent_lex= lex;
1101
957
  {
1102
958
    return(1);
1103
959
  }
1104
 
  TABLE_LIST *table_list= (TABLE_LIST*) select_lex->table_list.first;
 
960
  TableList *table_list= (TableList*) select_lex->table_list.first;
1105
961
  assert(table_list);
1106
962
  table_list->schema_select_lex= schema_select_lex;
1107
963
  table_list->schema_table_reformed= 1;
1123
979
    true  error;  In this case thd->fatal_error is set
1124
980
*/
1125
981
 
1126
 
bool alloc_query(THD *thd, const char *packet, uint packet_length)
 
982
bool alloc_query(THD *thd, const char *packet, uint32_t packet_length)
1127
983
{
1128
984
  /* Remove garbage at start and end of query */
1129
985
  while (packet_length > 0 && my_isspace(thd->charset(), packet[0]))
1140
996
  }
1141
997
  /* We must allocate some extra memory for query cache */
1142
998
  thd->query_length= 0;                        // Extra safety: Avoid races
1143
 
  if (!(thd->query= (char*) thd->memdup_w_gap((uchar*) (packet),
 
999
  if (!(thd->query= (char*) thd->memdup_w_gap((unsigned char*) (packet),
1144
1000
                                              packet_length,
1145
1001
                                              thd->db_length+ 1)))
1146
1002
    return true;
1212
1068
  /* first SELECT_LEX (have special meaning for many of non-SELECTcommands) */
1213
1069
  SELECT_LEX *select_lex= &lex->select_lex;
1214
1070
  /* first table of first SELECT_LEX */
1215
 
  TABLE_LIST *first_table= (TABLE_LIST*) select_lex->table_list.first;
 
1071
  TableList *first_table= (TableList*) select_lex->table_list.first;
1216
1072
  /* list of all tables in query */
1217
 
  TABLE_LIST *all_tables;
 
1073
  TableList *all_tables;
1218
1074
  /* most outer SELECT_LEX_UNIT of query */
1219
1075
  SELECT_LEX_UNIT *unit= &lex->unit;
1220
1076
  /* Saved variable value */
1239
1095
  all_tables= lex->query_tables;
1240
1096
  /* set context for commands which do not use setup_tables */
1241
1097
  select_lex->
1242
 
    context.resolve_in_table_list_only((TABLE_LIST*)select_lex->
 
1098
    context.resolve_in_table_list_only((TableList*)select_lex->
1243
1099
                                       table_list.first);
1244
1100
 
1245
1101
  /*
1250
1106
    Don't reset warnings when executing a stored routine.
1251
1107
  */
1252
1108
  if (all_tables || !lex->is_single_level_stmt())
1253
 
    mysql_reset_errors(thd, 0);
 
1109
    drizzle_reset_errors(thd, 0);
1254
1110
 
1255
1111
  if (unlikely(thd->slave_thread))
1256
1112
  {
1338
1194
  case SQLCOM_SHOW_FIELDS:
1339
1195
  case SQLCOM_SHOW_KEYS:
1340
1196
  case SQLCOM_SHOW_VARIABLES:
1341
 
  case SQLCOM_SHOW_CHARSETS:
1342
 
  case SQLCOM_SHOW_COLLATIONS:
1343
1197
  case SQLCOM_SELECT:
1344
1198
  {
1345
1199
    thd->status_var.last_query_cost= 0.0;
1378
1232
  }
1379
1233
  case SQLCOM_SHOW_WARNS:
1380
1234
  {
1381
 
    res= mysqld_show_warnings(thd, (ulong)
1382
 
                              ((1L << (uint) MYSQL_ERROR::WARN_LEVEL_NOTE) |
1383
 
                               (1L << (uint) MYSQL_ERROR::WARN_LEVEL_WARN) |
1384
 
                               (1L << (uint) MYSQL_ERROR::WARN_LEVEL_ERROR)
 
1235
    res= mysqld_show_warnings(thd, (uint32_t)
 
1236
                              ((1L << (uint32_t) DRIZZLE_ERROR::WARN_LEVEL_NOTE) |
 
1237
                               (1L << (uint32_t) DRIZZLE_ERROR::WARN_LEVEL_WARN) |
 
1238
                               (1L << (uint32_t) DRIZZLE_ERROR::WARN_LEVEL_ERROR)
1385
1239
                               ));
1386
1240
    break;
1387
1241
  }
1388
1242
  case SQLCOM_SHOW_ERRORS:
1389
1243
  {
1390
 
    res= mysqld_show_warnings(thd, (ulong)
1391
 
                              (1L << (uint) MYSQL_ERROR::WARN_LEVEL_ERROR));
1392
 
    break;
1393
 
  }
1394
 
  case SQLCOM_SHOW_SLAVE_HOSTS:
1395
 
  {
1396
 
    res = show_slave_hosts(thd);
1397
 
    break;
1398
 
  }
1399
 
  case SQLCOM_SHOW_BINLOG_EVENTS:
1400
 
  {
1401
 
    res = mysql_show_binlog_events(thd);
1402
 
    break;
1403
 
  }
1404
 
 
 
1244
    res= mysqld_show_warnings(thd, (uint32_t)
 
1245
                              (1L << (uint32_t) DRIZZLE_ERROR::WARN_LEVEL_ERROR));
 
1246
    break;
 
1247
  }
1405
1248
  case SQLCOM_ASSIGN_TO_KEYCACHE:
1406
1249
  {
1407
1250
    assert(first_table == all_tables && first_table != 0);
1424
1267
    }
1425
1268
    else
1426
1269
    {
1427
 
      push_warning(thd, MYSQL_ERROR::WARN_LEVEL_WARN, 0,
 
1270
      push_warning(thd, DRIZZLE_ERROR::WARN_LEVEL_WARN, 0,
1428
1271
                   "the master info structure does not exist");
1429
1272
      my_ok(thd);
1430
1273
    }
1456
1299
    assert(first_table == all_tables && first_table != 0);
1457
1300
    bool link_to_local;
1458
1301
    // Skip first table, which is the table we are creating
1459
 
    TABLE_LIST *create_table= lex->unlink_first_table(&link_to_local);
1460
 
    TABLE_LIST *select_tables= lex->query_tables;
 
1302
    TableList *create_table= lex->unlink_first_table(&link_to_local);
 
1303
    TableList *select_tables= lex->query_tables;
1461
1304
    /*
1462
1305
      Code below (especially in mysql_create_table() and select_create
1463
1306
      methods) may modify HA_CREATE_INFO structure in LEX, so we have to
1533
1376
      select_lex->options|= SELECT_NO_UNLOCK;
1534
1377
      unit->set_limit(select_lex);
1535
1378
 
1536
 
      /*
1537
 
        Disable non-empty MERGE tables with CREATE...SELECT. Too
1538
 
        complicated. See Bug #26379. Empty MERGE tables are read-only
1539
 
        and don't allow CREATE...SELECT anyway.
1540
 
      */
1541
 
      if (create_info.used_fields & HA_CREATE_USED_UNION)
1542
 
      {
1543
 
        my_error(ER_WRONG_OBJECT, MYF(0), create_table->db,
1544
 
                 create_table->table_name, "BASE TABLE");
1545
 
        res= 1;
1546
 
        goto end_with_restore_list;
1547
 
      }
1548
 
 
1549
1379
      if (!(create_info.options & HA_LEX_CREATE_TMP_TABLE))
1550
1380
      {
1551
1381
        lex->link_first_table_back(create_table, link_to_local);
1560
1390
        */
1561
1391
        if (!(create_info.options & HA_LEX_CREATE_TMP_TABLE))
1562
1392
        {
1563
 
          TABLE_LIST *duplicate;
 
1393
          TableList *duplicate;
1564
1394
          create_table= lex->unlink_first_table(&link_to_local);
1565
1395
          if ((duplicate= unique_table(thd, create_table, select_tables, 0)))
1566
1396
          {
1569
1399
            goto end_with_restore_list;
1570
1400
          }
1571
1401
        }
1572
 
        /* If we create merge table, we have to test tables in merge, too */
1573
 
        if (create_info.used_fields & HA_CREATE_USED_UNION)
1574
 
        {
1575
 
          TABLE_LIST *tab;
1576
 
          for (tab= (TABLE_LIST*) create_info.merge_list.first;
1577
 
               tab;
1578
 
               tab= tab->next_local)
1579
 
          {
1580
 
            TABLE_LIST *duplicate;
1581
 
            if ((duplicate= unique_table(thd, tab, select_tables, 0)))
1582
 
            {
1583
 
              update_non_unique_table_error(tab, "CREATE", duplicate);
1584
 
              res= 1;
1585
 
              goto end_with_restore_list;
1586
 
            }
1587
 
          }
1588
 
        }
1589
1402
 
1590
1403
        /*
1591
1404
          select_create is currently not re-execution friendly and
1657
1470
    assert(first_table == all_tables && first_table != 0);
1658
1471
    if (end_active_trans(thd))
1659
1472
      goto error;
1660
 
    /*
1661
 
      Currently CREATE INDEX or DROP INDEX cause a full table rebuild
1662
 
      and thus classify as slow administrative statements just like
1663
 
      ALTER TABLE.
1664
 
    */
1665
 
    thd->enable_slow_log= opt_log_slow_admin_statements;
1666
1473
 
1667
 
    bzero((char*) &create_info, sizeof(create_info));
 
1474
    memset(&create_info, 0, sizeof(create_info));
1668
1475
    create_info.db_type= 0;
1669
1476
    create_info.row_type= ROW_TYPE_NOT_USED;
1670
1477
    create_info.default_table_charset= thd->variables.collation_database;
1671
1478
 
1672
1479
    res= mysql_alter_table(thd, first_table->db, first_table->table_name,
1673
1480
                           &create_info, first_table, &alter_info,
1674
 
                           0, (ORDER*) 0, 0);
 
1481
                           0, (order_st*) 0, 0);
1675
1482
    break;
1676
1483
  }
1677
 
#ifdef HAVE_REPLICATION
1678
1484
  case SQLCOM_SLAVE_START:
1679
1485
  {
1680
1486
    pthread_mutex_lock(&LOCK_active_mi);
1708
1514
    pthread_mutex_unlock(&LOCK_active_mi);
1709
1515
    break;
1710
1516
  }
1711
 
#endif /* HAVE_REPLICATION */
1712
1517
 
1713
1518
  case SQLCOM_ALTER_TABLE:
1714
1519
    assert(first_table == all_tables && first_table != 0);
1731
1536
      assert(select_lex->db);
1732
1537
 
1733
1538
      { // Rename of table
1734
 
          TABLE_LIST tmp_table;
1735
 
          bzero((char*) &tmp_table,sizeof(tmp_table));
 
1539
          TableList tmp_table;
 
1540
          memset(&tmp_table, 0, sizeof(tmp_table));
1736
1541
          tmp_table.table_name= lex->name.str;
1737
1542
          tmp_table.db=select_lex->db;
1738
1543
      }
1739
1544
 
1740
1545
      /* Don't yet allow changing of symlinks with ALTER TABLE */
1741
1546
      if (create_info.data_file_name)
1742
 
        push_warning(thd, MYSQL_ERROR::WARN_LEVEL_WARN, 0,
 
1547
        push_warning(thd, DRIZZLE_ERROR::WARN_LEVEL_WARN, 0,
1743
1548
                     "DATA DIRECTORY option ignored");
1744
1549
      if (create_info.index_file_name)
1745
 
        push_warning(thd, MYSQL_ERROR::WARN_LEVEL_WARN, 0,
 
1550
        push_warning(thd, DRIZZLE_ERROR::WARN_LEVEL_WARN, 0,
1746
1551
                     "INDEX DIRECTORY option ignored");
1747
1552
      create_info.data_file_name= create_info.index_file_name= NULL;
1748
1553
      /* ALTER TABLE ends previous transaction */
1756
1561
        break;
1757
1562
      }
1758
1563
 
1759
 
      thd->enable_slow_log= opt_log_slow_admin_statements;
1760
1564
      res= mysql_alter_table(thd, select_lex->db, lex->name.str,
1761
1565
                             &create_info,
1762
1566
                             first_table,
1763
1567
                             &alter_info,
1764
1568
                             select_lex->order_list.elements,
1765
 
                             (ORDER *) select_lex->order_list.first,
 
1569
                             (order_st *) select_lex->order_list.first,
1766
1570
                             lex->ignore);
1767
1571
      break;
1768
1572
    }
1769
1573
  case SQLCOM_RENAME_TABLE:
1770
1574
  {
1771
1575
    assert(first_table == all_tables && first_table != 0);
1772
 
    TABLE_LIST *table;
 
1576
    TableList *table;
1773
1577
    for (table= first_table; table; table= table->next_local->next_local)
1774
1578
    {
1775
 
      TABLE_LIST old_list, new_list;
 
1579
      TableList old_list, new_list;
1776
1580
      /*
1777
1581
        we do not need initialize old_list and new_list because we will
1778
1582
        come table[0] and table->next[0] there
1807
1611
  case SQLCOM_REPAIR:
1808
1612
  {
1809
1613
    assert(first_table == all_tables && first_table != 0);
1810
 
    thd->enable_slow_log= opt_log_slow_admin_statements;
1811
1614
    res= mysql_repair_table(thd, first_table, &lex->check_opt);
1812
1615
    /* ! we write after unlocking the table */
1813
 
    if (!res && !lex->no_write_to_binlog)
1814
 
    {
1815
 
      /*
1816
 
        Presumably, REPAIR and binlog writing doesn't require synchronization
1817
 
      */
1818
 
      write_bin_log(thd, true, thd->query, thd->query_length);
1819
 
    }
1820
 
    select_lex->table_list.first= (uchar*) first_table;
 
1616
    /*
 
1617
      Presumably, REPAIR and binlog writing doesn't require synchronization
 
1618
    */
 
1619
    write_bin_log(thd, true, thd->query, thd->query_length);
 
1620
    select_lex->table_list.first= (unsigned char*) first_table;
1821
1621
    lex->query_tables=all_tables;
1822
1622
    break;
1823
1623
  }
1824
1624
  case SQLCOM_CHECK:
1825
1625
  {
1826
1626
    assert(first_table == all_tables && first_table != 0);
1827
 
    thd->enable_slow_log= opt_log_slow_admin_statements;
1828
1627
    res = mysql_check_table(thd, first_table, &lex->check_opt);
1829
 
    select_lex->table_list.first= (uchar*) first_table;
 
1628
    select_lex->table_list.first= (unsigned char*) first_table;
1830
1629
    lex->query_tables=all_tables;
1831
1630
    break;
1832
1631
  }
1833
1632
  case SQLCOM_ANALYZE:
1834
1633
  {
1835
1634
    assert(first_table == all_tables && first_table != 0);
1836
 
    thd->enable_slow_log= opt_log_slow_admin_statements;
1837
1635
    res= mysql_analyze_table(thd, first_table, &lex->check_opt);
1838
1636
    /* ! we write after unlocking the table */
1839
 
    if (!res && !lex->no_write_to_binlog)
1840
 
    {
1841
 
      /*
1842
 
        Presumably, ANALYZE and binlog writing doesn't require synchronization
1843
 
      */
1844
 
      write_bin_log(thd, true, thd->query, thd->query_length);
1845
 
    }
1846
 
    select_lex->table_list.first= (uchar*) first_table;
 
1637
    write_bin_log(thd, true, thd->query, thd->query_length);
 
1638
    select_lex->table_list.first= (unsigned char*) first_table;
1847
1639
    lex->query_tables=all_tables;
1848
1640
    break;
1849
1641
  }
1851
1643
  case SQLCOM_OPTIMIZE:
1852
1644
  {
1853
1645
    assert(first_table == all_tables && first_table != 0);
1854
 
    thd->enable_slow_log= opt_log_slow_admin_statements;
1855
 
    res= (specialflag & (SPECIAL_SAFE_MODE | SPECIAL_NO_NEW_FUNC)) ?
1856
 
      mysql_recreate_table(thd, first_table) :
1857
 
      mysql_optimize_table(thd, first_table, &lex->check_opt);
 
1646
    res= mysql_optimize_table(thd, first_table, &lex->check_opt);
1858
1647
    /* ! we write after unlocking the table */
1859
 
    if (!res && !lex->no_write_to_binlog)
1860
 
    {
1861
 
      /*
1862
 
        Presumably, OPTIMIZE and binlog writing doesn't require synchronization
1863
 
      */
1864
 
      write_bin_log(thd, true, thd->query, thd->query_length);
1865
 
    }
1866
 
    select_lex->table_list.first= (uchar*) first_table;
 
1648
    write_bin_log(thd, true, thd->query, thd->query_length);
 
1649
    select_lex->table_list.first= (unsigned char*) first_table;
1867
1650
    lex->query_tables=all_tables;
1868
1651
    break;
1869
1652
  }
1878
1661
                                  lex->value_list,
1879
1662
                                  select_lex->where,
1880
1663
                                  select_lex->order_list.elements,
1881
 
                                  (ORDER *) select_lex->order_list.first,
 
1664
                                  (order_st *) select_lex->order_list.first,
1882
1665
                                  unit->select_limit_cnt,
1883
1666
                                  lex->duplicates, lex->ignore));
1884
1667
    /* mysql_update return 2 if we need to switch to multi-update */
1899
1682
 
1900
1683
    res= mysql_multi_update_prepare(thd);
1901
1684
 
1902
 
#ifdef HAVE_REPLICATION
1903
1685
    /* Check slave filtering rules */
1904
1686
    if (unlikely(thd->slave_thread))
1905
1687
    {
1919
1701
    }
1920
1702
    else
1921
1703
    {
1922
 
#endif /* HAVE_REPLICATION */
1923
1704
      if (res)
1924
1705
        break;
1925
1706
      if (opt_readonly &&
1928
1709
        my_error(ER_OPTION_PREVENTS_STATEMENT, MYF(0), "--read-only");
1929
1710
        break;
1930
1711
      }
1931
 
#ifdef HAVE_REPLICATION
1932
1712
    }  /* unlikely */
1933
 
#endif
1934
1713
 
1935
1714
    res= mysql_multi_update(thd, all_tables,
1936
1715
                            &select_lex->item_list,
1987
1766
    if (!(res= open_and_lock_tables(thd, all_tables)))
1988
1767
    {
1989
1768
      /* Skip first table, which is the table we are inserting in */
1990
 
      TABLE_LIST *second_table= first_table->next_local;
1991
 
      select_lex->table_list.first= (uchar*) second_table;
 
1769
      TableList *second_table= first_table->next_local;
 
1770
      select_lex->table_list.first= (unsigned char*) second_table;
1992
1771
      select_lex->context.table_list= 
1993
1772
        select_lex->context.first_name_resolution_table= second_table;
1994
1773
      res= mysql_insert_select_prepare(thd);
2011
1790
            thd->lock)
2012
1791
        {
2013
1792
          /* INSERT ... SELECT should invalidate only the very first table */
2014
 
          TABLE_LIST *save_table= first_table->next_local;
 
1793
          TableList *save_table= first_table->next_local;
2015
1794
          first_table->next_local= 0;
2016
1795
          first_table->next_local= save_table;
2017
1796
        }
2018
1797
        delete sel_result;
2019
1798
      }
2020
1799
      /* revert changes for SP */
2021
 
      select_lex->table_list.first= (uchar*) first_table;
 
1800
      select_lex->table_list.first= (unsigned char*) first_table;
2022
1801
    }
2023
1802
 
2024
1803
    break;
2066
1845
  case SQLCOM_DELETE_MULTI:
2067
1846
  {
2068
1847
    assert(first_table == all_tables && first_table != 0);
2069
 
    TABLE_LIST *aux_tables=
2070
 
      (TABLE_LIST *)thd->lex->auxiliary_table_list.first;
 
1848
    TableList *aux_tables=
 
1849
      (TableList *)thd->lex->auxiliary_table_list.first;
2071
1850
    multi_delete *del_result;
2072
1851
 
2073
1852
    if (!thd->locked_tables &&
2086
1865
    if (add_item_to_list(thd, new Item_null()))
2087
1866
      goto error;
2088
1867
 
2089
 
    thd_proc_info(thd, "init");
 
1868
    thd->set_proc_info("init");
2090
1869
    if ((res= open_and_lock_tables(thd, all_tables)))
2091
1870
      break;
2092
1871
 
2101
1880
                        select_lex->with_wild,
2102
1881
                        select_lex->item_list,
2103
1882
                        select_lex->where,
2104
 
                        0, (ORDER *)NULL, (ORDER *)NULL, (Item *)NULL,
2105
 
                        (ORDER *)NULL,
 
1883
                        0, (order_st *)NULL, (order_st *)NULL, (Item *)NULL,
 
1884
                        (order_st *)NULL,
2106
1885
                        select_lex->options | thd->options |
2107
1886
                        SELECT_NO_JOIN_CACHE | SELECT_NO_UNLOCK |
2108
1887
                        OPTION_SETUP_TABLES_DONE,
2141
1920
      thd->options|= OPTION_KEEP_LOG;
2142
1921
    }
2143
1922
    /* DDL and binlog write order protected by LOCK_open */
2144
 
    res= mysql_rm_table(thd, first_table, lex->drop_if_exists,
2145
 
                        lex->drop_temporary);
 
1923
    res= mysql_rm_table(thd, first_table, lex->drop_if_exists, lex->drop_temporary);
2146
1924
  }
2147
1925
  break;
2148
1926
  case SQLCOM_SHOW_PROCESSLIST:
2149
 
    mysqld_list_processes(thd, NullS, lex->verbose);
 
1927
    mysqld_list_processes(thd, NULL, lex->verbose);
2150
1928
    break;
2151
1929
  case SQLCOM_SHOW_ENGINE_LOGS:
2152
1930
    {
2357
2135
      do_db/ignore_db. And as this query involves no tables, tables_ok()
2358
2136
      above was not called. So we have to check rules again here.
2359
2137
    */
2360
 
#ifdef HAVE_REPLICATION
2361
2138
    if (thd->slave_thread && 
2362
2139
        (!rpl_filter->db_ok(lex->name.str) ||
2363
2140
         !rpl_filter->db_ok_with_wild_table(lex->name.str)))
2365
2142
      my_message(ER_SLAVE_IGNORED_TABLE, ER(ER_SLAVE_IGNORED_TABLE), MYF(0));
2366
2143
      break;
2367
2144
    }
2368
 
#endif
2369
2145
    if (thd->locked_tables || thd->active_transaction())
2370
2146
    {
2371
2147
      my_message(ER_LOCK_OR_ACTIVE_TRANSACTION,
2375
2151
    res= mysql_rm_db(thd, lex->name.str, lex->drop_if_exists, 0);
2376
2152
    break;
2377
2153
  }
2378
 
  case SQLCOM_ALTER_DB_UPGRADE:
2379
 
  {
2380
 
    LEX_STRING *db= & lex->name;
2381
 
    if (end_active_trans(thd))
2382
 
    {
2383
 
      res= 1;
2384
 
      break;
2385
 
    }
2386
 
#ifdef HAVE_REPLICATION
2387
 
    if (thd->slave_thread && 
2388
 
       (!rpl_filter->db_ok(db->str) ||
2389
 
        !rpl_filter->db_ok_with_wild_table(db->str)))
2390
 
    {
2391
 
      res= 1;
2392
 
      my_message(ER_SLAVE_IGNORED_TABLE, ER(ER_SLAVE_IGNORED_TABLE), MYF(0));
2393
 
      break;
2394
 
    }
2395
 
#endif
2396
 
    if (check_db_name(db))
2397
 
    {
2398
 
      my_error(ER_WRONG_DB_NAME, MYF(0), db->str);
2399
 
      break;
2400
 
    }
2401
 
    if (thd->locked_tables || thd->active_transaction())
2402
 
    {
2403
 
      res= 1;
2404
 
      my_message(ER_LOCK_OR_ACTIVE_TRANSACTION,
2405
 
                 ER(ER_LOCK_OR_ACTIVE_TRANSACTION), MYF(0));
2406
 
      goto error;
2407
 
    }
2408
 
 
2409
 
    res= mysql_upgrade_db(thd, db);
2410
 
    if (!res)
2411
 
      my_ok(thd);
2412
 
    break;
2413
 
  }
2414
2154
  case SQLCOM_ALTER_DB:
2415
2155
  {
2416
2156
    LEX_STRING *db= &lex->name;
2427
2167
      do_db/ignore_db. And as this query involves no tables, tables_ok()
2428
2168
      above was not called. So we have to check rules again here.
2429
2169
    */
2430
 
#ifdef HAVE_REPLICATION
2431
2170
    if (thd->slave_thread &&
2432
2171
        (!rpl_filter->db_ok(db->str) ||
2433
2172
         !rpl_filter->db_ok_with_wild_table(db->str)))
2435
2174
      my_message(ER_SLAVE_IGNORED_TABLE, ER(ER_SLAVE_IGNORED_TABLE), MYF(0));
2436
2175
      break;
2437
2176
    }
2438
 
#endif
2439
2177
    if (thd->locked_tables || thd->active_transaction())
2440
2178
    {
2441
2179
      my_message(ER_LOCK_OR_ACTIVE_TRANSACTION,
2456
2194
    break;
2457
2195
  }
2458
2196
  case SQLCOM_RESET:
2459
 
    /*
2460
 
      RESET commands are never written to the binary log, so we have to
2461
 
      initialize this variable because RESET shares the same code as FLUSH
2462
 
    */
2463
 
    lex->no_write_to_binlog= 1;
2464
2197
  case SQLCOM_FLUSH:
2465
2198
  {
2466
2199
    bool write_to_binlog;
2478
2211
      /*
2479
2212
        Presumably, RESET and binlog writing doesn't require synchronization
2480
2213
      */
2481
 
      if (!lex->no_write_to_binlog && write_to_binlog)
2482
 
      {
2483
 
        write_bin_log(thd, false, thd->query, thd->query_length);
2484
 
      }
 
2214
      write_bin_log(thd, false, thd->query, thd->query_length);
2485
2215
      my_ok(thd);
2486
2216
    } 
2487
2217
    
2539
2269
    for (sv=thd->transaction.savepoints; sv; sv=sv->prev)
2540
2270
    {
2541
2271
      if (my_strnncoll(system_charset_info,
2542
 
                       (uchar *)lex->ident.str, lex->ident.length,
2543
 
                       (uchar *)sv->name, sv->length) == 0)
 
2272
                       (unsigned char *)lex->ident.str, lex->ident.length,
 
2273
                       (unsigned char *)sv->name, sv->length) == 0)
2544
2274
        break;
2545
2275
    }
2546
2276
    if (sv)
2561
2291
    for (sv=thd->transaction.savepoints; sv; sv=sv->prev)
2562
2292
    {
2563
2293
      if (my_strnncoll(system_charset_info,
2564
 
                       (uchar *)lex->ident.str, lex->ident.length,
2565
 
                       (uchar *)sv->name, sv->length) == 0)
 
2294
                       (unsigned char *)lex->ident.str, lex->ident.length,
 
2295
                       (unsigned char *)sv->name, sv->length) == 0)
2566
2296
        break;
2567
2297
    }
2568
2298
    if (sv)
2574
2304
        if (((thd->options & OPTION_KEEP_LOG) || 
2575
2305
             thd->transaction.all.modified_non_trans_table) &&
2576
2306
            !thd->slave_thread)
2577
 
          push_warning(thd, MYSQL_ERROR::WARN_LEVEL_WARN,
 
2307
          push_warning(thd, DRIZZLE_ERROR::WARN_LEVEL_WARN,
2578
2308
                       ER_WARNING_NOT_COMPLETE_ROLLBACK,
2579
2309
                       ER(ER_WARNING_NOT_COMPLETE_ROLLBACK));
2580
2310
        my_ok(thd);
2586
2316
    break;
2587
2317
  }
2588
2318
  case SQLCOM_SAVEPOINT:
2589
 
    if (!(thd->options & (OPTION_NOT_AUTOCOMMIT | OPTION_BEGIN) ||
2590
 
          thd->in_sub_stmt) || !opt_using_transactions)
 
2319
    if (!(thd->options & (OPTION_NOT_AUTOCOMMIT | OPTION_BEGIN)) || !opt_using_transactions)
2591
2320
      my_ok(thd);
2592
2321
    else
2593
2322
    {
2595
2324
      for (sv=&thd->transaction.savepoints; *sv; sv=&(*sv)->prev)
2596
2325
      {
2597
2326
        if (my_strnncoll(system_charset_info,
2598
 
                         (uchar *)lex->ident.str, lex->ident.length,
2599
 
                         (uchar *)(*sv)->name, (*sv)->length) == 0)
 
2327
                         (unsigned char *)lex->ident.str, lex->ident.length,
 
2328
                         (unsigned char *)(*sv)->name, (*sv)->length) == 0)
2600
2329
          break;
2601
2330
      }
2602
2331
      if (*sv) /* old savepoint of the same name exists */
2639
2368
    my_ok(thd);
2640
2369
    break;
2641
2370
  }
2642
 
  thd_proc_info(thd, "query end");
 
2371
  thd->set_proc_info("query end");
2643
2372
 
2644
2373
  /*
2645
2374
    Binlog-related cleanup:
2680
2409
  return(res || thd->is_error());
2681
2410
}
2682
2411
 
2683
 
 
2684
 
static bool execute_sqlcom_select(THD *thd, TABLE_LIST *all_tables)
 
2412
bool execute_sqlcom_select(THD *thd, TableList *all_tables)
2685
2413
{
2686
2414
  LEX   *lex= thd->lex;
2687
2415
  select_result *result=lex->result;
2710
2438
      if (lex->describe & DESCRIBE_EXTENDED)
2711
2439
      {
2712
2440
        char buff[1024];
2713
 
        String str(buff,(uint32) sizeof(buff), system_charset_info);
 
2441
        String str(buff,(uint32_t) sizeof(buff), system_charset_info);
2714
2442
        str.length(0);
2715
2443
        thd->lex->unit.print(&str, QT_ORDINARY);
2716
2444
        str.append('\0');
2717
 
        push_warning(thd, MYSQL_ERROR::WARN_LEVEL_NOTE,
 
2445
        push_warning(thd, DRIZZLE_ERROR::WARN_LEVEL_NOTE,
2718
2446
                     ER_YES, str.ptr());
2719
2447
      }
2720
2448
      if (res)
2752
2480
  - Passing to check_stack_overrun() prevents the compiler from removing it.
2753
2481
*/
2754
2482
bool check_stack_overrun(THD *thd, long margin,
2755
 
                         uchar *buf __attribute__((unused)))
 
2483
                         unsigned char *buf __attribute__((unused)))
2756
2484
{
2757
2485
  long stack_used;
2758
2486
  assert(thd == current_thd);
2774
2502
{
2775
2503
  LEX   *lex= current_thd->lex;
2776
2504
  ulong old_info=0;
2777
 
  if ((uint) *yystacksize >= MY_YACC_MAX)
 
2505
  if ((uint32_t) *yystacksize >= MY_YACC_MAX)
2778
2506
    return 1;
2779
2507
  if (!lex->yacc_yyvs)
2780
2508
    old_info= *yystacksize;
2781
2509
  *yystacksize= set_zone((*yystacksize)*2,MY_YACC_INIT,MY_YACC_MAX);
2782
 
  if (!(lex->yacc_yyvs= (uchar*)
 
2510
  if (!(lex->yacc_yyvs= (unsigned char*)
2783
2511
        my_realloc(lex->yacc_yyvs,
2784
2512
                   *yystacksize*sizeof(**yyvs),
2785
2513
                   MYF(MY_ALLOW_ZERO_PTR | MY_FREE_ON_ERROR))) ||
2786
 
      !(lex->yacc_yyss= (uchar*)
 
2514
      !(lex->yacc_yyss= (unsigned char*)
2787
2515
        my_realloc(lex->yacc_yyss,
2788
2516
                   *yystacksize*sizeof(**yyss),
2789
2517
                   MYF(MY_ALLOW_ZERO_PTR | MY_FREE_ON_ERROR))))
2790
2518
    return 1;
2791
2519
  if (old_info)
2792
2520
  {                                             // Copy old info from stack
2793
 
    memcpy(lex->yacc_yyss, (uchar*) *yyss, old_info*sizeof(**yyss));
2794
 
    memcpy(lex->yacc_yyvs, (uchar*) *yyvs, old_info*sizeof(**yyvs));
 
2521
    memcpy(lex->yacc_yyss, *yyss, old_info*sizeof(**yyss));
 
2522
    memcpy(lex->yacc_yyvs, *yyvs, old_info*sizeof(**yyvs));
2795
2523
  }
2796
2524
  *yyss=(short*) lex->yacc_yyss;
2797
2525
  *yyvs=(YYSTYPE*) lex->yacc_yyvs;
2815
2543
 
2816
2544
void mysql_reset_thd_for_next_command(THD *thd)
2817
2545
{
2818
 
  assert(! thd->in_sub_stmt);
2819
2546
  thd->free_list= 0;
2820
2547
  thd->select_number= 1;
2821
2548
  /*
2923
2650
  {
2924
2651
    if (lex->current_select->order_list.first && !lex->current_select->braces)
2925
2652
    {
2926
 
      my_error(ER_WRONG_USAGE, MYF(0), "UNION", "ORDER BY");
 
2653
      my_error(ER_WRONG_USAGE, MYF(0), "UNION", "order_st BY");
2927
2654
      return(1);
2928
2655
    }
2929
2656
    select_lex->include_neighbour(lex->current_select);
2969
2696
  lex->sql_command= SQLCOM_SELECT;
2970
2697
  tmp.str= (char*) var_name;
2971
2698
  tmp.length=strlen(var_name);
2972
 
  bzero((char*) &null_lex_string.str, sizeof(null_lex_string));
 
2699
  memset(&null_lex_string.str, 0, sizeof(null_lex_string));
2973
2700
  /*
2974
2701
    We set the name of Item to @@session.var_name because that then is used
2975
2702
    as the column name in the output.
2976
2703
  */
2977
2704
  if ((var= get_system_var(thd, OPT_SESSION, tmp, null_lex_string)))
2978
2705
  {
2979
 
    end= strxmov(buff, "@@session.", var_name, NullS);
 
2706
    end= strxmov(buff, "@@session.", var_name, NULL);
2980
2707
    var->set_name(buff, end-buff, system_charset_info);
2981
2708
    add_item_to_list(thd, var);
2982
2709
  }
3012
2739
                               the next query in the query text.
3013
2740
*/
3014
2741
 
3015
 
void mysql_parse(THD *thd, const char *inBuf, uint length,
 
2742
void mysql_parse(THD *thd, const char *inBuf, uint32_t length,
3016
2743
                 const char ** found_semicolon)
3017
2744
{
3018
2745
  /*
3039
2766
 
3040
2767
    Lex_input_stream lip(thd, inBuf, length);
3041
2768
 
3042
 
    bool err= parse_sql(thd, &lip, NULL);
 
2769
    bool err= parse_sql(thd, &lip);
3043
2770
    *found_semicolon= lip.found_semicolon;
3044
2771
 
3045
2772
    if (!err)
3070
2797
      assert(thd->is_error());
3071
2798
    }
3072
2799
    lex->unit.cleanup();
3073
 
    thd_proc_info(thd, "freeing items");
 
2800
    thd->set_proc_info("freeing items");
3074
2801
    thd->end_statement();
3075
2802
    thd->cleanup_after_query();
3076
2803
    assert(thd->change_list.is_empty());
3080
2807
}
3081
2808
 
3082
2809
 
3083
 
#ifdef HAVE_REPLICATION
3084
2810
/*
3085
2811
  Usable by the replication SQL thread only: just parse a query to know if it
3086
2812
  can be ignored because of replicate-*-table rules.
3091
2817
    1   can be ignored
3092
2818
*/
3093
2819
 
3094
 
bool mysql_test_parse_for_slave(THD *thd, char *inBuf, uint length)
 
2820
bool mysql_test_parse_for_slave(THD *thd, char *inBuf, uint32_t length)
3095
2821
{
3096
2822
  LEX *lex= thd->lex;
3097
2823
  bool error= 0;
3100
2826
  lex_start(thd);
3101
2827
  mysql_reset_thd_for_next_command(thd);
3102
2828
 
3103
 
  if (!parse_sql(thd, &lip, NULL) &&
3104
 
      all_tables_not_ok(thd,(TABLE_LIST*) lex->select_lex.table_list.first))
 
2829
  if (!parse_sql(thd, &lip) &&
 
2830
      all_tables_not_ok(thd,(TableList*) lex->select_lex.table_list.first))
3105
2831
    error= 1;                  /* Ignore question */
3106
2832
  thd->end_statement();
3107
2833
  thd->cleanup_after_query();
3108
2834
  return(error);
3109
2835
}
3110
 
#endif
3111
2836
 
3112
2837
 
3113
2838
 
3120
2845
 
3121
2846
bool add_field_to_list(THD *thd, LEX_STRING *field_name, enum_field_types type,
3122
2847
                       char *length, char *decimals,
3123
 
                       uint type_modifier,
 
2848
                       uint32_t type_modifier,
3124
2849
                       enum column_format_type column_format,
3125
2850
                       Item *default_value, Item *on_update_value,
3126
2851
                       LEX_STRING *comment,
3127
2852
                       char *change,
3128
 
                       List<String> *interval_list, CHARSET_INFO *cs)
 
2853
                       List<String> *interval_list, const CHARSET_INFO * const cs,
 
2854
                       virtual_column_info *vcol_info)
3129
2855
{
3130
2856
  register Create_field *new_field;
3131
2857
  LEX  *lex= thd->lex;
3165
2891
    */
3166
2892
    if (default_value->type() == Item::FUNC_ITEM && 
3167
2893
        !(((Item_func*)default_value)->functype() == Item_func::NOW_FUNC &&
3168
 
         type == MYSQL_TYPE_TIMESTAMP))
 
2894
         type == DRIZZLE_TYPE_TIMESTAMP))
3169
2895
    {
3170
2896
      my_error(ER_INVALID_DEFAULT, MYF(0), field_name->str);
3171
2897
      return(1);
3187
2913
    }
3188
2914
  }
3189
2915
 
3190
 
  if (on_update_value && type != MYSQL_TYPE_TIMESTAMP)
 
2916
  if (on_update_value && type != DRIZZLE_TYPE_TIMESTAMP)
3191
2917
  {
3192
2918
    my_error(ER_INVALID_ON_UPDATE, MYF(0), field_name->str);
3193
2919
    return(1);
3196
2922
  if (!(new_field= new Create_field()) ||
3197
2923
      new_field->init(thd, field_name->str, type, length, decimals, type_modifier,
3198
2924
                      default_value, on_update_value, comment, change,
3199
 
                      interval_list, cs, 0, column_format))
 
2925
                      interval_list, cs, 0, column_format,
 
2926
                      vcol_info))
3200
2927
    return(1);
3201
2928
 
3202
2929
  lex->alter_info.create_list.push_back(new_field);
3209
2936
 
3210
2937
void store_position_for_column(const char *name)
3211
2938
{
3212
 
  current_thd->lex->last_field->after=my_const_cast(char*) (name);
 
2939
  current_thd->lex->last_field->after=const_cast<char*> (name);
3213
2940
}
3214
2941
 
3215
2942
bool
3216
2943
add_proc_to_list(THD* thd, Item *item)
3217
2944
{
3218
 
  ORDER *order;
 
2945
  order_st *order;
3219
2946
  Item  **item_ptr;
3220
2947
 
3221
 
  if (!(order = (ORDER *) thd->alloc(sizeof(ORDER)+sizeof(Item*))))
 
2948
  if (!(order = (order_st *) thd->alloc(sizeof(order_st)+sizeof(Item*))))
3222
2949
    return 1;
3223
2950
  item_ptr = (Item**) (order+1);
3224
2951
  *item_ptr= item;
3225
2952
  order->item=item_ptr;
3226
2953
  order->free_me=0;
3227
 
  thd->lex->proc_list.link_in_list((uchar*) order,(uchar**) &order->next);
 
2954
  thd->lex->proc_list.link_in_list((unsigned char*) order,(unsigned char**) &order->next);
3228
2955
  return 0;
3229
2956
}
3230
2957
 
3235
2962
 
3236
2963
bool add_to_list(THD *thd, SQL_LIST &list,Item *item,bool asc)
3237
2964
{
3238
 
  ORDER *order;
3239
 
  if (!(order = (ORDER *) thd->alloc(sizeof(ORDER))))
 
2965
  order_st *order;
 
2966
  if (!(order = (order_st *) thd->alloc(sizeof(order_st))))
3240
2967
    return(1);
3241
2968
  order->item_ptr= item;
3242
2969
  order->item= &order->item_ptr;
3244
2971
  order->free_me=0;
3245
2972
  order->used=0;
3246
2973
  order->counter_used= 0;
3247
 
  list.link_in_list((uchar*) order,(uchar**) &order->next);
 
2974
  list.link_in_list((unsigned char*) order,(unsigned char**) &order->next);
3248
2975
  return(0);
3249
2976
}
3250
2977
 
3265
2992
  @retval
3266
2993
      0         Error
3267
2994
  @retval
3268
 
    \#  Pointer to TABLE_LIST element added to the total table list
 
2995
    \#  Pointer to TableList element added to the total table list
3269
2996
*/
3270
2997
 
3271
 
TABLE_LIST *st_select_lex::add_table_to_list(THD *thd,
 
2998
TableList *st_select_lex::add_table_to_list(THD *thd,
3272
2999
                                             Table_ident *table,
3273
3000
                                             LEX_STRING *alias,
3274
 
                                             ulong table_options,
 
3001
                                             uint32_t table_options,
3275
3002
                                             thr_lock_type lock_type,
3276
3003
                                             List<Index_hint> *index_hints_arg,
3277
3004
                                             LEX_STRING *option)
3278
3005
{
3279
 
  register TABLE_LIST *ptr;
3280
 
  TABLE_LIST *previous_table_ref; /* The table preceding the current one. */
 
3006
  register TableList *ptr;
 
3007
  TableList *previous_table_ref; /* The table preceding the current one. */
3281
3008
  char *alias_str;
3282
3009
  LEX *lex= thd->lex;
3283
3010
 
3309
3036
    if (!(alias_str= (char*) thd->memdup(alias_str,table->table.length+1)))
3310
3037
      return(0);
3311
3038
  }
3312
 
  if (!(ptr = (TABLE_LIST *) thd->calloc(sizeof(TABLE_LIST))))
 
3039
  if (!(ptr = (TableList *) thd->calloc(sizeof(TableList))))
3313
3040
    return(0);                          /* purecov: inspected */
3314
3041
  if (table->db.str)
3315
3042
  {
3362
3089
  /* check that used name is unique */
3363
3090
  if (lock_type != TL_IGNORE)
3364
3091
  {
3365
 
    TABLE_LIST *first_table= (TABLE_LIST*) table_list.first;
3366
 
    for (TABLE_LIST *tables= first_table ;
 
3092
    TableList *first_table= (TableList*) table_list.first;
 
3093
    for (TableList *tables= first_table ;
3367
3094
         tables ;
3368
3095
         tables=tables->next_local)
3369
3096
    {
3379
3106
  if (table_list.elements > 0)
3380
3107
  {
3381
3108
    /*
3382
 
      table_list.next points to the last inserted TABLE_LIST->next_local'
 
3109
      table_list.next points to the last inserted TableList->next_local'
3383
3110
      element
3384
3111
      We don't use the offsetof() macro here to avoid warnings from gcc
3385
3112
    */
3386
 
    previous_table_ref= (TABLE_LIST*) ((char*) table_list.next -
 
3113
    previous_table_ref= (TableList*) ((char*) table_list.next -
3387
3114
                                       ((char*) &(ptr->next_local) -
3388
3115
                                        (char*) ptr));
3389
3116
    /*
3390
3117
      Set next_name_resolution_table of the previous table reference to point
3391
3118
      to the current table reference. In effect the list
3392
 
      TABLE_LIST::next_name_resolution_table coincides with
3393
 
      TABLE_LIST::next_local. Later this may be changed in
 
3119
      TableList::next_name_resolution_table coincides with
 
3120
      TableList::next_local. Later this may be changed in
3394
3121
      store_top_level_join_columns() for NATURAL/USING joins.
3395
3122
    */
3396
3123
    previous_table_ref->next_name_resolution_table= ptr;
3402
3129
    previous table reference to 'ptr'. Here we also add one element to the
3403
3130
    list 'table_list'.
3404
3131
  */
3405
 
  table_list.link_in_list((uchar*) ptr, (uchar**) &ptr->next_local);
 
3132
  table_list.link_in_list((unsigned char*) ptr, (unsigned char**) &ptr->next_local);
3406
3133
  ptr->next_name_resolution_table= NULL;
3407
3134
  /* Link table in global list (all used tables) */
3408
3135
  lex->add_to_query_tables(ptr);
3413
3140
/**
3414
3141
  Initialize a new table list for a nested join.
3415
3142
 
3416
 
    The function initializes a structure of the TABLE_LIST type
 
3143
    The function initializes a structure of the TableList type
3417
3144
    for a nested join. It sets up its nested join list as empty.
3418
3145
    The created structure is added to the front of the current
3419
3146
    join list in the st_select_lex object. Then the function
3431
3158
 
3432
3159
bool st_select_lex::init_nested_join(THD *thd)
3433
3160
{
3434
 
  TABLE_LIST *ptr;
3435
 
  NESTED_JOIN *nested_join;
 
3161
  TableList *ptr;
 
3162
  nested_join_st *nested_join;
3436
3163
 
3437
 
  if (!(ptr= (TABLE_LIST*) thd->calloc(ALIGN_SIZE(sizeof(TABLE_LIST))+
3438
 
                                       sizeof(NESTED_JOIN))))
 
3164
  if (!(ptr= (TableList*) thd->calloc(ALIGN_SIZE(sizeof(TableList))+
 
3165
                                       sizeof(nested_join_st))))
3439
3166
    return(1);
3440
3167
  nested_join= ptr->nested_join=
3441
 
    ((NESTED_JOIN*) ((uchar*) ptr + ALIGN_SIZE(sizeof(TABLE_LIST))));
 
3168
    ((nested_join_st*) ((unsigned char*) ptr + ALIGN_SIZE(sizeof(TableList))));
3442
3169
 
3443
3170
  join_list->push_front(ptr);
3444
3171
  ptr->embedding= embedding;
3461
3188
  @param thd         current thread
3462
3189
 
3463
3190
  @return
3464
 
    - Pointer to TABLE_LIST element added to the total table list, if success
 
3191
    - Pointer to TableList element added to the total table list, if success
3465
3192
    - 0, otherwise
3466
3193
*/
3467
3194
 
3468
 
TABLE_LIST *st_select_lex::end_nested_join(THD *thd __attribute__((__unused__)))
 
3195
TableList *st_select_lex::end_nested_join(THD *thd __attribute__((unused)))
3469
3196
{
3470
 
  TABLE_LIST *ptr;
3471
 
  NESTED_JOIN *nested_join;
 
3197
  TableList *ptr;
 
3198
  nested_join_st *nested_join;
3472
3199
 
3473
3200
  assert(embedding);
3474
3201
  ptr= embedding;
3477
3204
  nested_join= ptr->nested_join;
3478
3205
  if (nested_join->join_list.elements == 1)
3479
3206
  {
3480
 
    TABLE_LIST *embedded= nested_join->join_list.head();
 
3207
    TableList *embedded= nested_join->join_list.head();
3481
3208
    join_list->pop();
3482
3209
    embedded->join_list= join_list;
3483
3210
    embedded->embedding= embedding;
3503
3230
  @retval
3504
3231
    0  Error
3505
3232
  @retval
3506
 
    \#  Pointer to TABLE_LIST element created for the new nested join
 
3233
    \#  Pointer to TableList element created for the new nested join
3507
3234
*/
3508
3235
 
3509
 
TABLE_LIST *st_select_lex::nest_last_join(THD *thd)
 
3236
TableList *st_select_lex::nest_last_join(THD *thd)
3510
3237
{
3511
 
  TABLE_LIST *ptr;
3512
 
  NESTED_JOIN *nested_join;
3513
 
  List<TABLE_LIST> *embedded_list;
 
3238
  TableList *ptr;
 
3239
  nested_join_st *nested_join;
 
3240
  List<TableList> *embedded_list;
3514
3241
 
3515
 
  if (!(ptr= (TABLE_LIST*) thd->calloc(ALIGN_SIZE(sizeof(TABLE_LIST))+
3516
 
                                       sizeof(NESTED_JOIN))))
 
3242
  if (!(ptr= (TableList*) thd->calloc(ALIGN_SIZE(sizeof(TableList))+
 
3243
                                       sizeof(nested_join_st))))
3517
3244
    return(0);
3518
3245
  nested_join= ptr->nested_join=
3519
 
    ((NESTED_JOIN*) ((uchar*) ptr + ALIGN_SIZE(sizeof(TABLE_LIST))));
 
3246
    ((nested_join_st*) ((unsigned char*) ptr + ALIGN_SIZE(sizeof(TableList))));
3520
3247
 
3521
3248
  ptr->embedding= embedding;
3522
3249
  ptr->join_list= join_list;
3524
3251
  embedded_list= &nested_join->join_list;
3525
3252
  embedded_list->empty();
3526
3253
 
3527
 
  for (uint i=0; i < 2; i++)
 
3254
  for (uint32_t i=0; i < 2; i++)
3528
3255
  {
3529
 
    TABLE_LIST *table= join_list->pop();
 
3256
    TableList *table= join_list->pop();
3530
3257
    table->join_list= embedded_list;
3531
3258
    table->embedding= ptr;
3532
3259
    embedded_list->push_back(table);
3561
3288
    None
3562
3289
*/
3563
3290
 
3564
 
void st_select_lex::add_joined_table(TABLE_LIST *table)
 
3291
void st_select_lex::add_joined_table(TableList *table)
3565
3292
{
3566
3293
  join_list->push_front(table);
3567
3294
  table->join_list= join_list;
3601
3328
    - 0, otherwise
3602
3329
*/
3603
3330
 
3604
 
TABLE_LIST *st_select_lex::convert_right_join()
 
3331
TableList *st_select_lex::convert_right_join()
3605
3332
{
3606
 
  TABLE_LIST *tab2= join_list->pop();
3607
 
  TABLE_LIST *tab1= join_list->pop();
 
3333
  TableList *tab2= join_list->pop();
 
3334
  TableList *tab1= join_list->pop();
3608
3335
 
3609
3336
  join_list->push_front(tab2);
3610
3337
  join_list->push_front(tab1);
3628
3355
{
3629
3356
  bool for_update= lock_type >= TL_READ_NO_INSERT;
3630
3357
 
3631
 
  for (TABLE_LIST *tables= (TABLE_LIST*) table_list.first;
 
3358
  for (TableList *tables= (TableList*) table_list.first;
3632
3359
       tables;
3633
3360
       tables= tables->next_local)
3634
3361
  {
3646
3373
    This object is created for any union construct containing a union
3647
3374
    operation and also for any single select union construct of the form
3648
3375
    @verbatim
3649
 
    (SELECT ... ORDER BY order_list [LIMIT n]) ORDER BY ... 
 
3376
    (SELECT ... order_st BY order_list [LIMIT n]) order_st BY ... 
3650
3377
    @endvarbatim
3651
3378
    or of the form
3652
3379
    @varbatim
3653
 
    (SELECT ... ORDER BY LIMIT n) ORDER BY ...
 
3380
    (SELECT ... order_st BY LIMIT n) order_st BY ...
3654
3381
    @endvarbatim
3655
3382
  
3656
3383
  @param thd_arg                   thread handle
3681
3408
  fake_select_lex->select_limit= 0;
3682
3409
 
3683
3410
  fake_select_lex->context.outer_context=first_sl->context.outer_context;
3684
 
  /* allow item list resolving in fake select for ORDER BY */
 
3411
  /* allow item list resolving in fake select for order_st BY */
3685
3412
  fake_select_lex->context.resolve_in_select_list= true;
3686
3413
  fake_select_lex->context.select_lex= fake_select_lex;
3687
3414
 
3689
3416
  {
3690
3417
    /* 
3691
3418
      This works only for 
3692
 
      (SELECT ... ORDER BY list [LIMIT n]) ORDER BY order_list [LIMIT m],
3693
 
      (SELECT ... LIMIT n) ORDER BY order_list [LIMIT m]
 
3419
      (SELECT ... order_st BY list [LIMIT n]) order_st BY order_list [LIMIT m],
 
3420
      (SELECT ... LIMIT n) order_st BY order_list [LIMIT m]
3694
3421
      just before the parser starts processing order_list
3695
3422
    */ 
3696
3423
    global_parameters= fake_select_lex;
3723
3450
 
3724
3451
bool
3725
3452
push_new_name_resolution_context(THD *thd,
3726
 
                                 TABLE_LIST *left_op, TABLE_LIST *right_op)
 
3453
                                 TableList *left_op, TableList *right_op)
3727
3454
{
3728
3455
  Name_resolution_context *on_context;
3729
3456
  if (!(on_context= new (thd->mem_root) Name_resolution_context))
3751
3478
    true   if all is OK
3752
3479
*/
3753
3480
 
3754
 
void add_join_on(TABLE_LIST *b, Item *expr)
 
3481
void add_join_on(TableList *b, Item *expr)
3755
3482
{
3756
3483
  if (expr)
3757
3484
  {
3804
3531
  @param using_fields    Field names from USING clause
3805
3532
*/
3806
3533
 
3807
 
void add_join_natural(TABLE_LIST *a, TABLE_LIST *b, List<String> *using_fields,
 
3534
void add_join_natural(TableList *a, TableList *b, List<String> *using_fields,
3808
3535
                      SELECT_LEX *lex)
3809
3536
{
3810
3537
  b->natural_join= a;
3831
3558
    @retval !=0  Error; thd->killed is set or thd->is_error() is true
3832
3559
*/
3833
3560
 
3834
 
bool reload_cache(THD *thd, ulong options, TABLE_LIST *tables,
 
3561
bool reload_cache(THD *thd, ulong options, TableList *tables,
3835
3562
                          bool *write_to_binlog)
3836
3563
{
3837
3564
  bool result=0;
3838
3565
  select_errors=0;                              /* Write if more errors */
3839
3566
  bool tmp_write_to_binlog= 1;
3840
3567
 
3841
 
  assert(!thd || !thd->in_sub_stmt);
3842
 
 
3843
3568
  if (options & REFRESH_LOG)
3844
3569
  {
3845
3570
    /*
3956
3681
    This is written such that we have a short lock on LOCK_thread_count
3957
3682
*/
3958
3683
 
3959
 
uint kill_one_thread(THD *thd __attribute__((__unused__)),
3960
 
                     ulong id, bool only_kill_query)
 
3684
static unsigned int
 
3685
kill_one_thread(THD *thd __attribute__((unused)),
 
3686
                ulong id, bool only_kill_query)
3961
3687
{
3962
3688
  THD *tmp;
3963
 
  uint error=ER_NO_SUCH_THREAD;
3964
 
  VOID(pthread_mutex_lock(&LOCK_thread_count)); // For unlink from list
 
3689
  uint32_t error=ER_NO_SUCH_THREAD;
 
3690
  pthread_mutex_lock(&LOCK_thread_count); // For unlink from list
3965
3691
  I_List_iterator<THD> it(threads);
3966
3692
  while ((tmp=it++))
3967
3693
  {
3973
3699
      break;
3974
3700
    }
3975
3701
  }
3976
 
  VOID(pthread_mutex_unlock(&LOCK_thread_count));
 
3702
  pthread_mutex_unlock(&LOCK_thread_count);
3977
3703
  if (tmp)
3978
3704
  {
3979
3705
    tmp->awake(only_kill_query ? THD::KILL_QUERY : THD::KILL_CONNECTION);
3996
3722
 
3997
3723
void sql_kill(THD *thd, ulong id, bool only_kill_query)
3998
3724
{
3999
 
  uint error;
 
3725
  uint32_t error;
4000
3726
  if (!(error= kill_one_thread(thd, id, only_kill_query)))
4001
3727
    my_ok(thd);
4002
3728
  else
4021
3747
    return 1;
4022
3748
  }
4023
3749
  /* Fix is using unix filename format on dos */
4024
 
  strmov(buff,*filename_ptr);
4025
 
  end=convert_dirname(buff, *filename_ptr, NullS);
 
3750
  my_stpcpy(buff,*filename_ptr);
 
3751
  end=convert_dirname(buff, *filename_ptr, NULL);
4026
3752
  if (!(ptr= (char*) thd->alloc((size_t) (end-buff) + strlen(table_name)+1)))
4027
3753
    return 1;                                   // End of memory
4028
3754
  *filename_ptr=ptr;
4029
 
  strxmov(ptr,buff,table_name,NullS);
 
3755
  strxmov(ptr,buff,table_name,NULL);
4030
3756
  return 0;
4031
3757
}
4032
3758
 
4049
3775
    char command[80];
4050
3776
    Lex_input_stream *lip= thd->m_lip;
4051
3777
    strmake(command, lip->yylval->symbol.str,
4052
 
            min(lip->yylval->symbol.length, sizeof(command)-1));
 
3778
            cmin((ulong)lip->yylval->symbol.length, sizeof(command)-1));
4053
3779
    my_error(ER_CANT_USE_OPTION_HERE, MYF(0), command);
4054
3780
    return 1;
4055
3781
  }
4137
3863
*/
4138
3864
 
4139
3865
bool multi_update_precheck(THD *thd,
4140
 
                           TABLE_LIST *tables __attribute__((__unused__)))
 
3866
                           TableList *tables __attribute__((unused)))
4141
3867
{
4142
3868
  const char *msg= 0;
4143
3869
  LEX *lex= thd->lex;
4174
3900
*/
4175
3901
 
4176
3902
bool multi_delete_precheck(THD *thd,
4177
 
                           TABLE_LIST *tables __attribute__((__unused__)))
 
3903
                           TableList *tables __attribute__((unused)))
4178
3904
{
4179
3905
  SELECT_LEX *select_lex= &thd->lex->select_lex;
4180
 
  TABLE_LIST **save_query_tables_own_last= thd->lex->query_tables_own_last;
 
3906
  TableList **save_query_tables_own_last= thd->lex->query_tables_own_last;
4181
3907
 
4182
3908
  thd->lex->query_tables_own_last= 0;
4183
3909
  thd->lex->query_tables_own_last= save_query_tables_own_last;
4209
3935
  @return Matching table, NULL otherwise.
4210
3936
*/
4211
3937
 
4212
 
static TABLE_LIST *multi_delete_table_match(LEX *lex __attribute__((__unused__)),
4213
 
                                            TABLE_LIST *tbl,
4214
 
                                            TABLE_LIST *tables)
 
3938
static TableList *multi_delete_table_match(LEX *lex __attribute__((unused)),
 
3939
                                            TableList *tbl,
 
3940
                                            TableList *tables)
4215
3941
{
4216
 
  TABLE_LIST *match= NULL;
 
3942
  TableList *match= NULL;
4217
3943
 
4218
 
  for (TABLE_LIST *elem= tables; elem; elem= elem->next_local)
 
3944
  for (TableList *elem= tables; elem; elem= elem->next_local)
4219
3945
  {
4220
3946
    int cmp;
4221
3947
 
4263
3989
 
4264
3990
bool multi_delete_set_locks_and_link_aux_tables(LEX *lex)
4265
3991
{
4266
 
  TABLE_LIST *tables= (TABLE_LIST*)lex->select_lex.table_list.first;
4267
 
  TABLE_LIST *target_tbl;
 
3992
  TableList *tables= (TableList*)lex->select_lex.table_list.first;
 
3993
  TableList *target_tbl;
4268
3994
 
4269
3995
  lex->table_count= 0;
4270
3996
 
4271
 
  for (target_tbl= (TABLE_LIST *)lex->auxiliary_table_list.first;
 
3997
  for (target_tbl= (TableList *)lex->auxiliary_table_list.first;
4272
3998
       target_tbl; target_tbl= target_tbl->next_local)
4273
3999
  {
4274
4000
    lex->table_count++;
4275
4001
    /* All tables in aux_tables must be found in FROM PART */
4276
 
    TABLE_LIST *walk= multi_delete_table_match(lex, target_tbl, tables);
 
4002
    TableList *walk= multi_delete_table_match(lex, target_tbl, tables);
4277
4003
    if (!walk)
4278
4004
      return(true);
4279
4005
    if (!walk->derived)
4301
4027
    true  Error
4302
4028
*/
4303
4029
 
4304
 
bool update_precheck(THD *thd, TABLE_LIST *tables __attribute__((__unused__)))
 
4030
bool update_precheck(THD *thd, TableList *tables __attribute__((unused)))
4305
4031
{
4306
4032
  if (thd->lex->select_lex.item_list.elements != thd->lex->value_list.elements)
4307
4033
  {
4324
4050
    true   error
4325
4051
*/
4326
4052
 
4327
 
bool insert_precheck(THD *thd, TABLE_LIST *tables __attribute__((__unused__)))
 
4053
bool insert_precheck(THD *thd, TableList *tables __attribute__((unused)))
4328
4054
{
4329
4055
  LEX *lex= thd->lex;
4330
4056
 
4354
4080
    true   Error
4355
4081
*/
4356
4082
 
4357
 
bool create_table_precheck(THD *thd,
4358
 
                           TABLE_LIST *tables __attribute__((__unused__)),
4359
 
                           TABLE_LIST *create_table)
 
4083
bool create_table_precheck(THD *thd __attribute__((unused)),
 
4084
                           TableList *tables __attribute__((unused)),
 
4085
                           TableList *create_table)
4360
4086
{
4361
 
  LEX *lex= thd->lex;
4362
 
  SELECT_LEX *select_lex= &lex->select_lex;
4363
4087
  bool error= true;                                 // Error message is given
4364
4088
 
4365
4089
  if (create_table && (strcmp(create_table->db, "information_schema") == 0))
4368
4092
    return(true);
4369
4093
  }
4370
4094
 
4371
 
  if (select_lex->item_list.elements)
4372
 
  {
4373
 
    /* Check permissions for used tables in CREATE TABLE ... SELECT */
4374
 
 
4375
 
#ifdef NOT_NECESSARY_TO_CHECK_CREATE_TABLE_EXIST_WHEN_PREPARING_STATEMENT
4376
 
    /* This code throws an ill error for CREATE TABLE t1 SELECT * FROM t1 */
4377
 
    /*
4378
 
      Only do the check for PS, because we on execute we have to check that
4379
 
      against the opened tables to ensure we don't use a table that is part
4380
 
      of the view (which can only be done after the table has been opened).
4381
 
    */
4382
 
    if (thd->stmt_arena->is_stmt_prepare_or_first_sp_execute())
4383
 
    {
4384
 
      /*
4385
 
        For temporary tables we don't have to check if the created table exists
4386
 
      */
4387
 
      if (!(lex->create_info.options & HA_LEX_CREATE_TMP_TABLE) &&
4388
 
          find_table_in_global_list(tables, create_table->db,
4389
 
                                    create_table->table_name))
4390
 
      {
4391
 
        error= false;
4392
 
        goto err;
4393
 
      }
4394
 
    }
4395
 
#endif
4396
 
  }
4397
4095
  error= false;
4398
4096
 
4399
4097
  return(error);
4451
4149
*/
4452
4150
 
4453
4151
bool check_string_byte_length(LEX_STRING *str, const char *err_msg,
4454
 
                              uint max_byte_length)
 
4152
                              uint32_t max_byte_length)
4455
4153
{
4456
4154
  if (str->length <= max_byte_length)
4457
4155
    return false;
4479
4177
 
4480
4178
 
4481
4179
bool check_string_char_length(LEX_STRING *str, const char *err_msg,
4482
 
                              uint max_char_length, CHARSET_INFO *cs,
 
4180
                              uint32_t max_char_length, const CHARSET_INFO * const cs,
4483
4181
                              bool no_error)
4484
4182
{
4485
4183
  int well_formed_error;
4486
 
  uint res= cs->cset->well_formed_len(cs, str->str, str->str + str->length,
 
4184
  uint32_t res= cs->cset->well_formed_len(cs, str->str, str->str + str->length,
4487
4185
                                      max_char_length, &well_formed_error);
4488
4186
 
4489
4187
  if (!well_formed_error &&  str->length == res)
4495
4193
}
4496
4194
 
4497
4195
 
4498
 
bool check_identifier_name(LEX_STRING *str, uint max_char_length,
4499
 
                           uint err_code, const char *param_for_err_msg)
 
4196
bool check_identifier_name(LEX_STRING *str, uint32_t max_char_length,
 
4197
                           uint32_t err_code, const char *param_for_err_msg)
4500
4198
{
4501
4199
#ifdef HAVE_CHARSET_utf8mb3
4502
4200
  /*
4504
4202
    so they should be prohibited until such support is done.
4505
4203
    This is why we use the 3-byte utf8 to check well-formedness here.
4506
4204
  */
4507
 
  CHARSET_INFO *cs= &my_charset_utf8mb3_general_ci;
 
4205
  const CHARSET_INFO * const cs= &my_charset_utf8mb3_general_ci;
4508
4206
#else
4509
 
  CHARSET_INFO *cs= system_charset_info;
 
4207
  const CHARSET_INFO * const cs= system_charset_info;
4510
4208
#endif
4511
4209
  int well_formed_error;
4512
 
  uint res= cs->cset->well_formed_len(cs, str->str, str->str + str->length,
 
4210
  uint32_t res= cs->cset->well_formed_len(cs, str->str, str->str + str->length,
4513
4211
                                      max_char_length, &well_formed_error);
4514
4212
 
4515
4213
  if (well_formed_error)
4555
4253
bool test_if_data_home_dir(const char *dir)
4556
4254
{
4557
4255
  char path[FN_REFLEN], conv_path[FN_REFLEN];
4558
 
  uint dir_len, home_dir_len= strlen(mysql_unpacked_real_data_home);
 
4256
  uint32_t dir_len, home_dir_len= strlen(mysql_unpacked_real_data_home);
4559
4257
 
4560
4258
  if (!dir)
4561
4259
    return(0);
4566
4264
 
4567
4265
  if (home_dir_len < dir_len)
4568
4266
  {
4569
 
    if (lower_case_file_system)
4570
 
    {
4571
 
      if (!my_strnncoll(character_set_filesystem,
4572
 
                        (const uchar*) conv_path, home_dir_len,
4573
 
                        (const uchar*) mysql_unpacked_real_data_home,
4574
 
                        home_dir_len))
4575
 
        return(1);
4576
 
    }
4577
 
    else if (!memcmp(conv_path, mysql_unpacked_real_data_home, home_dir_len))
 
4267
    if (!my_strnncoll(character_set_filesystem,
 
4268
                      (const unsigned char*) conv_path, home_dir_len,
 
4269
                      (const unsigned char*) mysql_unpacked_real_data_home,
 
4270
                      home_dir_len))
4578
4271
      return(1);
4579
4272
  }
4580
4273
  return(0);
4590
4283
 
4591
4284
  @param thd Thread context.
4592
4285
  @param lip Lexer context.
4593
 
  @param creation_ctx Object creation context.
4594
4286
 
4595
4287
  @return Error status.
4596
4288
    @retval false on success.
4597
4289
    @retval true on parsing error.
4598
4290
*/
4599
4291
 
4600
 
bool parse_sql(THD *thd,
4601
 
               Lex_input_stream *lip,
4602
 
               Object_creation_ctx *creation_ctx)
 
4292
bool parse_sql(THD *thd, Lex_input_stream *lip)
4603
4293
{
4604
4294
  assert(thd->m_lip == NULL);
4605
4295
 
4606
 
  /* Backup creation context. */
4607
 
 
4608
 
  Object_creation_ctx *backup_ctx= NULL;
4609
 
 
4610
 
  if (creation_ctx)
4611
 
    backup_ctx= creation_ctx->set_n_backup(thd);
4612
 
 
4613
4296
  /* Set Lex_input_stream. */
4614
4297
 
4615
4298
  thd->m_lip= lip;
4626
4309
 
4627
4310
  thd->m_lip= NULL;
4628
4311
 
4629
 
  /* Restore creation context. */
4630
 
 
4631
 
  if (creation_ctx)
4632
 
    creation_ctx->restore_env(thd, backup_ctx);
4633
 
 
4634
4312
  /* That's it. */
4635
4313
 
4636
4314
  return mysql_parse_status || thd->is_fatal_error;