~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to server/sql_parse.cc

Merged.

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