~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/sql_parse.cc

  • Committer: Stewart Smith
  • Date: 2008-09-15 07:13:59 UTC
  • mfrom: (383.1.21 drizzle)
  • mto: This revision was merged to the branch mainline in revision 408.
  • Revision ID: stewart@flamingspork.com-20080915071359-f8bznznyaiqrtqxa
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 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
20
#include "repl_failsafe.h"
 
21
#include <drizzled/drizzled_error_messages.h>
21
22
 
22
23
/**
23
24
  @defgroup Runtime_Environment Runtime Environment
37
38
  { C_STRING_WITH_LEN("Drop DB") },
38
39
  { C_STRING_WITH_LEN("Refresh") },
39
40
  { C_STRING_WITH_LEN("Shutdown") },
40
 
  { C_STRING_WITH_LEN("Statistics") },
41
41
  { C_STRING_WITH_LEN("Processlist") },
42
42
  { C_STRING_WITH_LEN("Connect") },
43
43
  { C_STRING_WITH_LEN("Kill") },
118
118
    LEX *lex= thd->lex;
119
119
    thd->options|= OPTION_BEGIN;
120
120
    thd->server_status|= SERVER_STATUS_IN_TRANS;
121
 
    if (lex->start_transaction_opt & MYSQL_START_TRANS_OPT_WITH_CONS_SNAPSHOT)
 
121
    if (lex->start_transaction_opt & DRIZZLE_START_TRANS_OPT_WITH_CONS_SNAPSHOT)
122
122
      error= ha_start_consistent_snapshot(thd);
123
123
  }
124
124
  return error;
127
127
/**
128
128
  Returns true if all tables should be ignored.
129
129
*/
130
 
inline bool all_tables_not_ok(THD *thd, TABLE_LIST *tables)
 
130
inline bool all_tables_not_ok(THD *thd, TableList *tables)
131
131
{
132
132
  return rpl_filter->is_on() && tables &&
133
133
         !rpl_filter->tables_ok(thd->db, tables);
134
134
}
135
135
 
136
136
 
137
 
static bool some_non_temp_table_to_be_updated(THD *thd, TABLE_LIST *tables)
 
137
static bool some_non_temp_table_to_be_updated(THD *thd, TableList *tables)
138
138
{
139
 
  for (TABLE_LIST *table= tables; table; table= table->next_global)
 
139
  for (TableList *table= tables; table; table= table->next_global)
140
140
  {
141
141
    assert(table->db && table->table_name);
142
142
    if (table->updating &&
164
164
 
165
165
void init_update_queries(void)
166
166
{
167
 
  memset((uchar*) &sql_command_flags, 0, sizeof(sql_command_flags));
 
167
  memset(&sql_command_flags, 0, sizeof(sql_command_flags));
168
168
 
169
169
  sql_command_flags[SQLCOM_CREATE_TABLE]=   CF_CHANGES_DATA;
170
170
  sql_command_flags[SQLCOM_CREATE_INDEX]=   CF_CHANGES_DATA;
441
441
*/
442
442
 
443
443
static bool deny_updates_if_read_only_option(THD *thd,
444
 
                                                TABLE_LIST *all_tables)
 
444
                                                TableList *all_tables)
445
445
{
446
446
  if (!opt_readonly)
447
447
    return(false);
525
525
 
526
526
  switch( command ) {
527
527
  /* Ignore these statements. */
528
 
  case COM_STATISTICS:
529
528
  case COM_PING:
530
529
    break;
531
530
  /* Increase id and count all other statements. */
565
564
    status_var_increment(thd->status_var.com_other);
566
565
    char *user= (char*) packet, *packet_end= packet + packet_length;
567
566
    /* Safe because there is always a trailing \0 at the end of the packet */
568
 
    char *passwd= strend(user)+1;
 
567
    char *passwd= strchr(user, '\0')+1;
 
568
 
569
569
 
570
570
    thd->clear_error();                         // if errors from rollback
571
571
 
642
642
 
643
643
    /* Clear variables that are allocated */
644
644
    thd->user_connect= 0;
645
 
    thd->security_ctx->priv_user= thd->security_ctx->user;
646
645
    res= check_user(thd, COM_CHANGE_USER, passwd, passwd_len, db, false);
647
646
 
648
647
    if (res)
717
716
  {
718
717
    char *fields, *packet_end= packet + packet_length, *arg_end;
719
718
    /* Locked closure of all tables */
720
 
    TABLE_LIST table_list;
 
719
    TableList table_list;
721
720
    LEX_STRING conv_name;
722
721
 
723
722
    /* used as fields initializator */
724
723
    lex_start(thd);
725
724
 
726
725
    status_var_increment(thd->status_var.com_stat[SQLCOM_SHOW_FIELDS]);
727
 
    memset((char*) &table_list, 0, sizeof(table_list));
 
726
    memset(&table_list, 0, sizeof(table_list));
728
727
    if (thd->copy_db_to(&table_list.db, &table_list.db_length))
729
728
      break;
730
729
    /*
731
730
      We have name + wildcard in packet, separated by endzero
732
731
    */
733
 
    arg_end= strend(packet);
 
732
    arg_end= strchr(packet, '\0');
734
733
    thd->convert_string(&conv_name, system_charset_info,
735
734
                        packet, (uint) (arg_end - packet), thd->charset());
736
735
    table_list.alias= table_list.table_name= conv_name.str;
825
824
    error=true;
826
825
    break;
827
826
  }
828
 
  case COM_STATISTICS:
829
 
  {
830
 
    STATUS_VAR current_global_status_var;
831
 
    ulong uptime;
832
 
    uint length;
833
 
    uint64_t queries_per_second1000;
834
 
    char buff[250];
835
 
    uint buff_len= sizeof(buff);
836
 
 
837
 
    general_log_print(thd, command, NullS);
838
 
    status_var_increment(thd->status_var.com_stat[SQLCOM_SHOW_STATUS]);
839
 
    calc_sum_of_all_status(&current_global_status_var);
840
 
    if (!(uptime= (ulong) (thd->start_time - server_start_time)))
841
 
      queries_per_second1000= 0;
842
 
    else
843
 
      queries_per_second1000= thd->query_id * 1000LL / uptime;
844
 
 
845
 
    length= snprintf((char*) buff, buff_len - 1,
846
 
                     "Uptime: %lu  Threads: %d  Questions: %lu  "
847
 
                     "Slow queries: %lu  Opens: %lu  Flush tables: %lu  "
848
 
                     "Open tables: %u  Queries per second avg: %u.%u",
849
 
                     uptime,
850
 
                     (int) thread_count, (ulong) thd->query_id,
851
 
                     current_global_status_var.long_query_count,
852
 
                     current_global_status_var.opened_tables,
853
 
                     refresh_version,
854
 
                     cached_open_tables(),
855
 
                     (uint) (queries_per_second1000 / 1000),
856
 
                     (uint) (queries_per_second1000 % 1000));
857
 
    /* Store the buffer in permanent memory */
858
 
    my_ok(thd, 0, 0, buff);
859
 
    VOID(my_net_write(net, (uchar*) buff, length));
860
 
    VOID(net_flush(net));
861
 
    thd->main_da.disable_status();
862
 
    break;
863
 
  }
864
827
  case COM_PING:
865
828
    status_var_increment(thd->status_var.com_other);
866
829
    my_ok(thd);                         // Tell client we are alive
883
846
    uint opt_command= uint2korr(packet);
884
847
 
885
848
    switch (opt_command) {
886
 
    case (int) MYSQL_OPTION_MULTI_STATEMENTS_ON:
 
849
    case (int) DRIZZLE_OPTION_MULTI_STATEMENTS_ON:
887
850
      thd->client_capabilities|= CLIENT_MULTI_STATEMENTS;
888
851
      my_eof(thd);
889
852
      break;
890
 
    case (int) MYSQL_OPTION_MULTI_STATEMENTS_OFF:
 
853
    case (int) DRIZZLE_OPTION_MULTI_STATEMENTS_OFF:
891
854
      thd->client_capabilities&= ~CLIENT_MULTI_STATEMENTS;
892
855
      my_eof(thd);
893
856
      break;
928
891
 
929
892
  net_end_statement(thd);
930
893
 
931
 
  thd->proc_info= "closing tables";
 
894
  thd->set_proc_info("closing tables");
932
895
  /* Free tables */
933
896
  close_thread_tables(thd);
934
897
 
985
948
 
986
949
 
987
950
/**
988
 
  Create a TABLE_LIST object for an INFORMATION_SCHEMA table.
 
951
  Create a TableList object for an INFORMATION_SCHEMA table.
989
952
 
990
953
    This function is used in the parser to convert a SHOW or DESCRIBE
991
954
    table_name command to a SELECT from INFORMATION_SCHEMA.
992
 
    It prepares a SELECT_LEX and a TABLE_LIST object to represent the
 
955
    It prepares a SELECT_LEX and a TableList object to represent the
993
956
    given command as a SELECT parse tree.
994
957
 
995
958
  @param thd              thread handle
1044
1007
  case SCH_STATISTICS:
1045
1008
  {
1046
1009
    assert(table_ident);
1047
 
    TABLE_LIST **query_tables_last= lex->query_tables_last;
 
1010
    TableList **query_tables_last= lex->query_tables_last;
1048
1011
    schema_select_lex= new SELECT_LEX();
1049
1012
    /* 'parent_lex' is used in init_query() so it must be before it. */
1050
1013
    schema_select_lex->parent_lex= lex;
1072
1035
  {
1073
1036
    return(1);
1074
1037
  }
1075
 
  TABLE_LIST *table_list= (TABLE_LIST*) select_lex->table_list.first;
 
1038
  TableList *table_list= (TableList*) select_lex->table_list.first;
1076
1039
  assert(table_list);
1077
1040
  table_list->schema_select_lex= schema_select_lex;
1078
1041
  table_list->schema_table_reformed= 1;
1183
1146
  /* first SELECT_LEX (have special meaning for many of non-SELECTcommands) */
1184
1147
  SELECT_LEX *select_lex= &lex->select_lex;
1185
1148
  /* first table of first SELECT_LEX */
1186
 
  TABLE_LIST *first_table= (TABLE_LIST*) select_lex->table_list.first;
 
1149
  TableList *first_table= (TableList*) select_lex->table_list.first;
1187
1150
  /* list of all tables in query */
1188
 
  TABLE_LIST *all_tables;
 
1151
  TableList *all_tables;
1189
1152
  /* most outer SELECT_LEX_UNIT of query */
1190
1153
  SELECT_LEX_UNIT *unit= &lex->unit;
1191
1154
  /* Saved variable value */
1210
1173
  all_tables= lex->query_tables;
1211
1174
  /* set context for commands which do not use setup_tables */
1212
1175
  select_lex->
1213
 
    context.resolve_in_table_list_only((TABLE_LIST*)select_lex->
 
1176
    context.resolve_in_table_list_only((TableList*)select_lex->
1214
1177
                                       table_list.first);
1215
1178
 
1216
1179
  /*
1221
1184
    Don't reset warnings when executing a stored routine.
1222
1185
  */
1223
1186
  if (all_tables || !lex->is_single_level_stmt())
1224
 
    mysql_reset_errors(thd, 0);
 
1187
    drizzle_reset_errors(thd, 0);
1225
1188
 
1226
1189
  if (unlikely(thd->slave_thread))
1227
1190
  {
1349
1312
  }
1350
1313
  case SQLCOM_SHOW_WARNS:
1351
1314
  {
1352
 
    res= mysqld_show_warnings(thd, (ulong)
1353
 
                              ((1L << (uint) MYSQL_ERROR::WARN_LEVEL_NOTE) |
1354
 
                               (1L << (uint) MYSQL_ERROR::WARN_LEVEL_WARN) |
1355
 
                               (1L << (uint) MYSQL_ERROR::WARN_LEVEL_ERROR)
 
1315
    res= mysqld_show_warnings(thd, (uint32_t)
 
1316
                              ((1L << (uint) DRIZZLE_ERROR::WARN_LEVEL_NOTE) |
 
1317
                               (1L << (uint) DRIZZLE_ERROR::WARN_LEVEL_WARN) |
 
1318
                               (1L << (uint) DRIZZLE_ERROR::WARN_LEVEL_ERROR)
1356
1319
                               ));
1357
1320
    break;
1358
1321
  }
1359
1322
  case SQLCOM_SHOW_ERRORS:
1360
1323
  {
1361
 
    res= mysqld_show_warnings(thd, (ulong)
1362
 
                              (1L << (uint) MYSQL_ERROR::WARN_LEVEL_ERROR));
 
1324
    res= mysqld_show_warnings(thd, (uint32_t)
 
1325
                              (1L << (uint) DRIZZLE_ERROR::WARN_LEVEL_ERROR));
1363
1326
    break;
1364
1327
  }
1365
1328
  case SQLCOM_SHOW_SLAVE_HOSTS:
1395
1358
    }
1396
1359
    else
1397
1360
    {
1398
 
      push_warning(thd, MYSQL_ERROR::WARN_LEVEL_WARN, 0,
 
1361
      push_warning(thd, DRIZZLE_ERROR::WARN_LEVEL_WARN, 0,
1399
1362
                   "the master info structure does not exist");
1400
1363
      my_ok(thd);
1401
1364
    }
1427
1390
    assert(first_table == all_tables && first_table != 0);
1428
1391
    bool link_to_local;
1429
1392
    // Skip first table, which is the table we are creating
1430
 
    TABLE_LIST *create_table= lex->unlink_first_table(&link_to_local);
1431
 
    TABLE_LIST *select_tables= lex->query_tables;
 
1393
    TableList *create_table= lex->unlink_first_table(&link_to_local);
 
1394
    TableList *select_tables= lex->query_tables;
1432
1395
    /*
1433
1396
      Code below (especially in mysql_create_table() and select_create
1434
1397
      methods) may modify HA_CREATE_INFO structure in LEX, so we have to
1504
1467
      select_lex->options|= SELECT_NO_UNLOCK;
1505
1468
      unit->set_limit(select_lex);
1506
1469
 
1507
 
      /*
1508
 
        Disable non-empty MERGE tables with CREATE...SELECT. Too
1509
 
        complicated. See Bug #26379. Empty MERGE tables are read-only
1510
 
        and don't allow CREATE...SELECT anyway.
1511
 
      */
1512
 
      if (create_info.used_fields & HA_CREATE_USED_UNION)
1513
 
      {
1514
 
        my_error(ER_WRONG_OBJECT, MYF(0), create_table->db,
1515
 
                 create_table->table_name, "BASE TABLE");
1516
 
        res= 1;
1517
 
        goto end_with_restore_list;
1518
 
      }
1519
 
 
1520
1470
      if (!(create_info.options & HA_LEX_CREATE_TMP_TABLE))
1521
1471
      {
1522
1472
        lex->link_first_table_back(create_table, link_to_local);
1531
1481
        */
1532
1482
        if (!(create_info.options & HA_LEX_CREATE_TMP_TABLE))
1533
1483
        {
1534
 
          TABLE_LIST *duplicate;
 
1484
          TableList *duplicate;
1535
1485
          create_table= lex->unlink_first_table(&link_to_local);
1536
1486
          if ((duplicate= unique_table(thd, create_table, select_tables, 0)))
1537
1487
          {
1540
1490
            goto end_with_restore_list;
1541
1491
          }
1542
1492
        }
1543
 
        /* If we create merge table, we have to test tables in merge, too */
1544
 
        if (create_info.used_fields & HA_CREATE_USED_UNION)
1545
 
        {
1546
 
          TABLE_LIST *tab;
1547
 
          for (tab= (TABLE_LIST*) create_info.merge_list.first;
1548
 
               tab;
1549
 
               tab= tab->next_local)
1550
 
          {
1551
 
            TABLE_LIST *duplicate;
1552
 
            if ((duplicate= unique_table(thd, tab, select_tables, 0)))
1553
 
            {
1554
 
              update_non_unique_table_error(tab, "CREATE", duplicate);
1555
 
              res= 1;
1556
 
              goto end_with_restore_list;
1557
 
            }
1558
 
          }
1559
 
        }
1560
1493
 
1561
1494
        /*
1562
1495
          select_create is currently not re-execution friendly and
1635
1568
    */
1636
1569
    thd->enable_slow_log= opt_log_slow_admin_statements;
1637
1570
 
1638
 
    memset((char*) &create_info, 0, sizeof(create_info));
 
1571
    memset(&create_info, 0, sizeof(create_info));
1639
1572
    create_info.db_type= 0;
1640
1573
    create_info.row_type= ROW_TYPE_NOT_USED;
1641
1574
    create_info.default_table_charset= thd->variables.collation_database;
1642
1575
 
1643
1576
    res= mysql_alter_table(thd, first_table->db, first_table->table_name,
1644
1577
                           &create_info, first_table, &alter_info,
1645
 
                           0, (ORDER*) 0, 0);
 
1578
                           0, (order_st*) 0, 0);
1646
1579
    break;
1647
1580
  }
1648
1581
  case SQLCOM_SLAVE_START:
1700
1633
      assert(select_lex->db);
1701
1634
 
1702
1635
      { // Rename of table
1703
 
          TABLE_LIST tmp_table;
1704
 
          memset((char*) &tmp_table, 0, sizeof(tmp_table));
 
1636
          TableList tmp_table;
 
1637
          memset(&tmp_table, 0, sizeof(tmp_table));
1705
1638
          tmp_table.table_name= lex->name.str;
1706
1639
          tmp_table.db=select_lex->db;
1707
1640
      }
1708
1641
 
1709
1642
      /* Don't yet allow changing of symlinks with ALTER TABLE */
1710
1643
      if (create_info.data_file_name)
1711
 
        push_warning(thd, MYSQL_ERROR::WARN_LEVEL_WARN, 0,
 
1644
        push_warning(thd, DRIZZLE_ERROR::WARN_LEVEL_WARN, 0,
1712
1645
                     "DATA DIRECTORY option ignored");
1713
1646
      if (create_info.index_file_name)
1714
 
        push_warning(thd, MYSQL_ERROR::WARN_LEVEL_WARN, 0,
 
1647
        push_warning(thd, DRIZZLE_ERROR::WARN_LEVEL_WARN, 0,
1715
1648
                     "INDEX DIRECTORY option ignored");
1716
1649
      create_info.data_file_name= create_info.index_file_name= NULL;
1717
1650
      /* ALTER TABLE ends previous transaction */
1731
1664
                             first_table,
1732
1665
                             &alter_info,
1733
1666
                             select_lex->order_list.elements,
1734
 
                             (ORDER *) select_lex->order_list.first,
 
1667
                             (order_st *) select_lex->order_list.first,
1735
1668
                             lex->ignore);
1736
1669
      break;
1737
1670
    }
1738
1671
  case SQLCOM_RENAME_TABLE:
1739
1672
  {
1740
1673
    assert(first_table == all_tables && first_table != 0);
1741
 
    TABLE_LIST *table;
 
1674
    TableList *table;
1742
1675
    for (table= first_table; table; table= table->next_local->next_local)
1743
1676
    {
1744
 
      TABLE_LIST old_list, new_list;
 
1677
      TableList old_list, new_list;
1745
1678
      /*
1746
1679
        we do not need initialize old_list and new_list because we will
1747
1680
        come table[0] and table->next[0] there
1821
1754
  {
1822
1755
    assert(first_table == all_tables && first_table != 0);
1823
1756
    thd->enable_slow_log= opt_log_slow_admin_statements;
1824
 
    res= (specialflag & (SPECIAL_SAFE_MODE | SPECIAL_NO_NEW_FUNC)) ?
1825
 
      mysql_recreate_table(thd, first_table) :
1826
 
      mysql_optimize_table(thd, first_table, &lex->check_opt);
 
1757
    res= mysql_optimize_table(thd, first_table, &lex->check_opt);
1827
1758
    /* ! we write after unlocking the table */
1828
1759
    if (!res && !lex->no_write_to_binlog)
1829
1760
    {
1847
1778
                                  lex->value_list,
1848
1779
                                  select_lex->where,
1849
1780
                                  select_lex->order_list.elements,
1850
 
                                  (ORDER *) select_lex->order_list.first,
 
1781
                                  (order_st *) select_lex->order_list.first,
1851
1782
                                  unit->select_limit_cnt,
1852
1783
                                  lex->duplicates, lex->ignore));
1853
1784
    /* mysql_update return 2 if we need to switch to multi-update */
1952
1883
    if (!(res= open_and_lock_tables(thd, all_tables)))
1953
1884
    {
1954
1885
      /* Skip first table, which is the table we are inserting in */
1955
 
      TABLE_LIST *second_table= first_table->next_local;
 
1886
      TableList *second_table= first_table->next_local;
1956
1887
      select_lex->table_list.first= (uchar*) second_table;
1957
1888
      select_lex->context.table_list= 
1958
1889
        select_lex->context.first_name_resolution_table= second_table;
1976
1907
            thd->lock)
1977
1908
        {
1978
1909
          /* INSERT ... SELECT should invalidate only the very first table */
1979
 
          TABLE_LIST *save_table= first_table->next_local;
 
1910
          TableList *save_table= first_table->next_local;
1980
1911
          first_table->next_local= 0;
1981
1912
          first_table->next_local= save_table;
1982
1913
        }
2031
1962
  case SQLCOM_DELETE_MULTI:
2032
1963
  {
2033
1964
    assert(first_table == all_tables && first_table != 0);
2034
 
    TABLE_LIST *aux_tables=
2035
 
      (TABLE_LIST *)thd->lex->auxiliary_table_list.first;
 
1965
    TableList *aux_tables=
 
1966
      (TableList *)thd->lex->auxiliary_table_list.first;
2036
1967
    multi_delete *del_result;
2037
1968
 
2038
1969
    if (!thd->locked_tables &&
2066
1997
                        select_lex->with_wild,
2067
1998
                        select_lex->item_list,
2068
1999
                        select_lex->where,
2069
 
                        0, (ORDER *)NULL, (ORDER *)NULL, (Item *)NULL,
2070
 
                        (ORDER *)NULL,
 
2000
                        0, (order_st *)NULL, (order_st *)NULL, (Item *)NULL,
 
2001
                        (order_st *)NULL,
2071
2002
                        select_lex->options | thd->options |
2072
2003
                        SELECT_NO_JOIN_CACHE | SELECT_NO_UNLOCK |
2073
2004
                        OPTION_SETUP_TABLES_DONE,
2498
2429
        if (((thd->options & OPTION_KEEP_LOG) || 
2499
2430
             thd->transaction.all.modified_non_trans_table) &&
2500
2431
            !thd->slave_thread)
2501
 
          push_warning(thd, MYSQL_ERROR::WARN_LEVEL_WARN,
 
2432
          push_warning(thd, DRIZZLE_ERROR::WARN_LEVEL_WARN,
2502
2433
                       ER_WARNING_NOT_COMPLETE_ROLLBACK,
2503
2434
                       ER(ER_WARNING_NOT_COMPLETE_ROLLBACK));
2504
2435
        my_ok(thd);
2604
2535
  return(res || thd->is_error());
2605
2536
}
2606
2537
 
2607
 
bool execute_sqlcom_select(THD *thd, TABLE_LIST *all_tables)
 
2538
bool execute_sqlcom_select(THD *thd, TableList *all_tables)
2608
2539
{
2609
2540
  LEX   *lex= thd->lex;
2610
2541
  select_result *result=lex->result;
2637
2568
        str.length(0);
2638
2569
        thd->lex->unit.print(&str, QT_ORDINARY);
2639
2570
        str.append('\0');
2640
 
        push_warning(thd, MYSQL_ERROR::WARN_LEVEL_NOTE,
 
2571
        push_warning(thd, DRIZZLE_ERROR::WARN_LEVEL_NOTE,
2641
2572
                     ER_YES, str.ptr());
2642
2573
      }
2643
2574
      if (res)
2713
2644
    return 1;
2714
2645
  if (old_info)
2715
2646
  {                                             // Copy old info from stack
2716
 
    memcpy(lex->yacc_yyss, (uchar*) *yyss, old_info*sizeof(**yyss));
2717
 
    memcpy(lex->yacc_yyvs, (uchar*) *yyvs, old_info*sizeof(**yyvs));
 
2647
    memcpy(lex->yacc_yyss, *yyss, old_info*sizeof(**yyss));
 
2648
    memcpy(lex->yacc_yyvs, *yyvs, old_info*sizeof(**yyvs));
2718
2649
  }
2719
2650
  *yyss=(short*) lex->yacc_yyss;
2720
2651
  *yyvs=(YYSTYPE*) lex->yacc_yyvs;
2846
2777
  {
2847
2778
    if (lex->current_select->order_list.first && !lex->current_select->braces)
2848
2779
    {
2849
 
      my_error(ER_WRONG_USAGE, MYF(0), "UNION", "ORDER BY");
 
2780
      my_error(ER_WRONG_USAGE, MYF(0), "UNION", "order_st BY");
2850
2781
      return(1);
2851
2782
    }
2852
2783
    select_lex->include_neighbour(lex->current_select);
2892
2823
  lex->sql_command= SQLCOM_SELECT;
2893
2824
  tmp.str= (char*) var_name;
2894
2825
  tmp.length=strlen(var_name);
2895
 
  memset((char*) &null_lex_string.str, 0, sizeof(null_lex_string));
 
2826
  memset(&null_lex_string.str, 0, sizeof(null_lex_string));
2896
2827
  /*
2897
2828
    We set the name of Item to @@session.var_name because that then is used
2898
2829
    as the column name in the output.
2962
2893
 
2963
2894
    Lex_input_stream lip(thd, inBuf, length);
2964
2895
 
2965
 
    bool err= parse_sql(thd, &lip, NULL);
 
2896
    bool err= parse_sql(thd, &lip);
2966
2897
    *found_semicolon= lip.found_semicolon;
2967
2898
 
2968
2899
    if (!err)
3022
2953
  lex_start(thd);
3023
2954
  mysql_reset_thd_for_next_command(thd);
3024
2955
 
3025
 
  if (!parse_sql(thd, &lip, NULL) &&
3026
 
      all_tables_not_ok(thd,(TABLE_LIST*) lex->select_lex.table_list.first))
 
2956
  if (!parse_sql(thd, &lip) &&
 
2957
      all_tables_not_ok(thd,(TableList*) lex->select_lex.table_list.first))
3027
2958
    error= 1;                  /* Ignore question */
3028
2959
  thd->end_statement();
3029
2960
  thd->cleanup_after_query();
3046
2977
                       Item *default_value, Item *on_update_value,
3047
2978
                       LEX_STRING *comment,
3048
2979
                       char *change,
3049
 
                       List<String> *interval_list, CHARSET_INFO *cs)
 
2980
                       List<String> *interval_list, const CHARSET_INFO * const cs)
3050
2981
{
3051
2982
  register Create_field *new_field;
3052
2983
  LEX  *lex= thd->lex;
3136
3067
bool
3137
3068
add_proc_to_list(THD* thd, Item *item)
3138
3069
{
3139
 
  ORDER *order;
 
3070
  order_st *order;
3140
3071
  Item  **item_ptr;
3141
3072
 
3142
 
  if (!(order = (ORDER *) thd->alloc(sizeof(ORDER)+sizeof(Item*))))
 
3073
  if (!(order = (order_st *) thd->alloc(sizeof(order_st)+sizeof(Item*))))
3143
3074
    return 1;
3144
3075
  item_ptr = (Item**) (order+1);
3145
3076
  *item_ptr= item;
3156
3087
 
3157
3088
bool add_to_list(THD *thd, SQL_LIST &list,Item *item,bool asc)
3158
3089
{
3159
 
  ORDER *order;
3160
 
  if (!(order = (ORDER *) thd->alloc(sizeof(ORDER))))
 
3090
  order_st *order;
 
3091
  if (!(order = (order_st *) thd->alloc(sizeof(order_st))))
3161
3092
    return(1);
3162
3093
  order->item_ptr= item;
3163
3094
  order->item= &order->item_ptr;
3186
3117
  @retval
3187
3118
      0         Error
3188
3119
  @retval
3189
 
    \#  Pointer to TABLE_LIST element added to the total table list
 
3120
    \#  Pointer to TableList element added to the total table list
3190
3121
*/
3191
3122
 
3192
 
TABLE_LIST *st_select_lex::add_table_to_list(THD *thd,
 
3123
TableList *st_select_lex::add_table_to_list(THD *thd,
3193
3124
                                             Table_ident *table,
3194
3125
                                             LEX_STRING *alias,
3195
3126
                                             uint32_t table_options,
3197
3128
                                             List<Index_hint> *index_hints_arg,
3198
3129
                                             LEX_STRING *option)
3199
3130
{
3200
 
  register TABLE_LIST *ptr;
3201
 
  TABLE_LIST *previous_table_ref; /* The table preceding the current one. */
 
3131
  register TableList *ptr;
 
3132
  TableList *previous_table_ref; /* The table preceding the current one. */
3202
3133
  char *alias_str;
3203
3134
  LEX *lex= thd->lex;
3204
3135
 
3230
3161
    if (!(alias_str= (char*) thd->memdup(alias_str,table->table.length+1)))
3231
3162
      return(0);
3232
3163
  }
3233
 
  if (!(ptr = (TABLE_LIST *) thd->calloc(sizeof(TABLE_LIST))))
 
3164
  if (!(ptr = (TableList *) thd->calloc(sizeof(TableList))))
3234
3165
    return(0);                          /* purecov: inspected */
3235
3166
  if (table->db.str)
3236
3167
  {
3283
3214
  /* check that used name is unique */
3284
3215
  if (lock_type != TL_IGNORE)
3285
3216
  {
3286
 
    TABLE_LIST *first_table= (TABLE_LIST*) table_list.first;
3287
 
    for (TABLE_LIST *tables= first_table ;
 
3217
    TableList *first_table= (TableList*) table_list.first;
 
3218
    for (TableList *tables= first_table ;
3288
3219
         tables ;
3289
3220
         tables=tables->next_local)
3290
3221
    {
3300
3231
  if (table_list.elements > 0)
3301
3232
  {
3302
3233
    /*
3303
 
      table_list.next points to the last inserted TABLE_LIST->next_local'
 
3234
      table_list.next points to the last inserted TableList->next_local'
3304
3235
      element
3305
3236
      We don't use the offsetof() macro here to avoid warnings from gcc
3306
3237
    */
3307
 
    previous_table_ref= (TABLE_LIST*) ((char*) table_list.next -
 
3238
    previous_table_ref= (TableList*) ((char*) table_list.next -
3308
3239
                                       ((char*) &(ptr->next_local) -
3309
3240
                                        (char*) ptr));
3310
3241
    /*
3311
3242
      Set next_name_resolution_table of the previous table reference to point
3312
3243
      to the current table reference. In effect the list
3313
 
      TABLE_LIST::next_name_resolution_table coincides with
3314
 
      TABLE_LIST::next_local. Later this may be changed in
 
3244
      TableList::next_name_resolution_table coincides with
 
3245
      TableList::next_local. Later this may be changed in
3315
3246
      store_top_level_join_columns() for NATURAL/USING joins.
3316
3247
    */
3317
3248
    previous_table_ref->next_name_resolution_table= ptr;
3334
3265
/**
3335
3266
  Initialize a new table list for a nested join.
3336
3267
 
3337
 
    The function initializes a structure of the TABLE_LIST type
 
3268
    The function initializes a structure of the TableList type
3338
3269
    for a nested join. It sets up its nested join list as empty.
3339
3270
    The created structure is added to the front of the current
3340
3271
    join list in the st_select_lex object. Then the function
3352
3283
 
3353
3284
bool st_select_lex::init_nested_join(THD *thd)
3354
3285
{
3355
 
  TABLE_LIST *ptr;
3356
 
  NESTED_JOIN *nested_join;
 
3286
  TableList *ptr;
 
3287
  nested_join_st *nested_join;
3357
3288
 
3358
 
  if (!(ptr= (TABLE_LIST*) thd->calloc(ALIGN_SIZE(sizeof(TABLE_LIST))+
3359
 
                                       sizeof(NESTED_JOIN))))
 
3289
  if (!(ptr= (TableList*) thd->calloc(ALIGN_SIZE(sizeof(TableList))+
 
3290
                                       sizeof(nested_join_st))))
3360
3291
    return(1);
3361
3292
  nested_join= ptr->nested_join=
3362
 
    ((NESTED_JOIN*) ((uchar*) ptr + ALIGN_SIZE(sizeof(TABLE_LIST))));
 
3293
    ((nested_join_st*) ((uchar*) ptr + ALIGN_SIZE(sizeof(TableList))));
3363
3294
 
3364
3295
  join_list->push_front(ptr);
3365
3296
  ptr->embedding= embedding;
3382
3313
  @param thd         current thread
3383
3314
 
3384
3315
  @return
3385
 
    - Pointer to TABLE_LIST element added to the total table list, if success
 
3316
    - Pointer to TableList element added to the total table list, if success
3386
3317
    - 0, otherwise
3387
3318
*/
3388
3319
 
3389
 
TABLE_LIST *st_select_lex::end_nested_join(THD *thd __attribute__((unused)))
 
3320
TableList *st_select_lex::end_nested_join(THD *thd __attribute__((unused)))
3390
3321
{
3391
 
  TABLE_LIST *ptr;
3392
 
  NESTED_JOIN *nested_join;
 
3322
  TableList *ptr;
 
3323
  nested_join_st *nested_join;
3393
3324
 
3394
3325
  assert(embedding);
3395
3326
  ptr= embedding;
3398
3329
  nested_join= ptr->nested_join;
3399
3330
  if (nested_join->join_list.elements == 1)
3400
3331
  {
3401
 
    TABLE_LIST *embedded= nested_join->join_list.head();
 
3332
    TableList *embedded= nested_join->join_list.head();
3402
3333
    join_list->pop();
3403
3334
    embedded->join_list= join_list;
3404
3335
    embedded->embedding= embedding;
3424
3355
  @retval
3425
3356
    0  Error
3426
3357
  @retval
3427
 
    \#  Pointer to TABLE_LIST element created for the new nested join
 
3358
    \#  Pointer to TableList element created for the new nested join
3428
3359
*/
3429
3360
 
3430
 
TABLE_LIST *st_select_lex::nest_last_join(THD *thd)
 
3361
TableList *st_select_lex::nest_last_join(THD *thd)
3431
3362
{
3432
 
  TABLE_LIST *ptr;
3433
 
  NESTED_JOIN *nested_join;
3434
 
  List<TABLE_LIST> *embedded_list;
 
3363
  TableList *ptr;
 
3364
  nested_join_st *nested_join;
 
3365
  List<TableList> *embedded_list;
3435
3366
 
3436
 
  if (!(ptr= (TABLE_LIST*) thd->calloc(ALIGN_SIZE(sizeof(TABLE_LIST))+
3437
 
                                       sizeof(NESTED_JOIN))))
 
3367
  if (!(ptr= (TableList*) thd->calloc(ALIGN_SIZE(sizeof(TableList))+
 
3368
                                       sizeof(nested_join_st))))
3438
3369
    return(0);
3439
3370
  nested_join= ptr->nested_join=
3440
 
    ((NESTED_JOIN*) ((uchar*) ptr + ALIGN_SIZE(sizeof(TABLE_LIST))));
 
3371
    ((nested_join_st*) ((uchar*) ptr + ALIGN_SIZE(sizeof(TableList))));
3441
3372
 
3442
3373
  ptr->embedding= embedding;
3443
3374
  ptr->join_list= join_list;
3447
3378
 
3448
3379
  for (uint i=0; i < 2; i++)
3449
3380
  {
3450
 
    TABLE_LIST *table= join_list->pop();
 
3381
    TableList *table= join_list->pop();
3451
3382
    table->join_list= embedded_list;
3452
3383
    table->embedding= ptr;
3453
3384
    embedded_list->push_back(table);
3482
3413
    None
3483
3414
*/
3484
3415
 
3485
 
void st_select_lex::add_joined_table(TABLE_LIST *table)
 
3416
void st_select_lex::add_joined_table(TableList *table)
3486
3417
{
3487
3418
  join_list->push_front(table);
3488
3419
  table->join_list= join_list;
3522
3453
    - 0, otherwise
3523
3454
*/
3524
3455
 
3525
 
TABLE_LIST *st_select_lex::convert_right_join()
 
3456
TableList *st_select_lex::convert_right_join()
3526
3457
{
3527
 
  TABLE_LIST *tab2= join_list->pop();
3528
 
  TABLE_LIST *tab1= join_list->pop();
 
3458
  TableList *tab2= join_list->pop();
 
3459
  TableList *tab1= join_list->pop();
3529
3460
 
3530
3461
  join_list->push_front(tab2);
3531
3462
  join_list->push_front(tab1);
3549
3480
{
3550
3481
  bool for_update= lock_type >= TL_READ_NO_INSERT;
3551
3482
 
3552
 
  for (TABLE_LIST *tables= (TABLE_LIST*) table_list.first;
 
3483
  for (TableList *tables= (TableList*) table_list.first;
3553
3484
       tables;
3554
3485
       tables= tables->next_local)
3555
3486
  {
3567
3498
    This object is created for any union construct containing a union
3568
3499
    operation and also for any single select union construct of the form
3569
3500
    @verbatim
3570
 
    (SELECT ... ORDER BY order_list [LIMIT n]) ORDER BY ... 
 
3501
    (SELECT ... order_st BY order_list [LIMIT n]) order_st BY ... 
3571
3502
    @endvarbatim
3572
3503
    or of the form
3573
3504
    @varbatim
3574
 
    (SELECT ... ORDER BY LIMIT n) ORDER BY ...
 
3505
    (SELECT ... order_st BY LIMIT n) order_st BY ...
3575
3506
    @endvarbatim
3576
3507
  
3577
3508
  @param thd_arg                   thread handle
3602
3533
  fake_select_lex->select_limit= 0;
3603
3534
 
3604
3535
  fake_select_lex->context.outer_context=first_sl->context.outer_context;
3605
 
  /* allow item list resolving in fake select for ORDER BY */
 
3536
  /* allow item list resolving in fake select for order_st BY */
3606
3537
  fake_select_lex->context.resolve_in_select_list= true;
3607
3538
  fake_select_lex->context.select_lex= fake_select_lex;
3608
3539
 
3610
3541
  {
3611
3542
    /* 
3612
3543
      This works only for 
3613
 
      (SELECT ... ORDER BY list [LIMIT n]) ORDER BY order_list [LIMIT m],
3614
 
      (SELECT ... LIMIT n) ORDER BY order_list [LIMIT m]
 
3544
      (SELECT ... order_st BY list [LIMIT n]) order_st BY order_list [LIMIT m],
 
3545
      (SELECT ... LIMIT n) order_st BY order_list [LIMIT m]
3615
3546
      just before the parser starts processing order_list
3616
3547
    */ 
3617
3548
    global_parameters= fake_select_lex;
3644
3575
 
3645
3576
bool
3646
3577
push_new_name_resolution_context(THD *thd,
3647
 
                                 TABLE_LIST *left_op, TABLE_LIST *right_op)
 
3578
                                 TableList *left_op, TableList *right_op)
3648
3579
{
3649
3580
  Name_resolution_context *on_context;
3650
3581
  if (!(on_context= new (thd->mem_root) Name_resolution_context))
3672
3603
    true   if all is OK
3673
3604
*/
3674
3605
 
3675
 
void add_join_on(TABLE_LIST *b, Item *expr)
 
3606
void add_join_on(TableList *b, Item *expr)
3676
3607
{
3677
3608
  if (expr)
3678
3609
  {
3725
3656
  @param using_fields    Field names from USING clause
3726
3657
*/
3727
3658
 
3728
 
void add_join_natural(TABLE_LIST *a, TABLE_LIST *b, List<String> *using_fields,
 
3659
void add_join_natural(TableList *a, TableList *b, List<String> *using_fields,
3729
3660
                      SELECT_LEX *lex)
3730
3661
{
3731
3662
  b->natural_join= a;
3752
3683
    @retval !=0  Error; thd->killed is set or thd->is_error() is true
3753
3684
*/
3754
3685
 
3755
 
bool reload_cache(THD *thd, ulong options, TABLE_LIST *tables,
 
3686
bool reload_cache(THD *thd, ulong options, TableList *tables,
3756
3687
                          bool *write_to_binlog)
3757
3688
{
3758
3689
  bool result=0;
3943
3874
    return 1;
3944
3875
  }
3945
3876
  /* Fix is using unix filename format on dos */
3946
 
  strmov(buff,*filename_ptr);
 
3877
  stpcpy(buff,*filename_ptr);
3947
3878
  end=convert_dirname(buff, *filename_ptr, NullS);
3948
3879
  if (!(ptr= (char*) thd->alloc((size_t) (end-buff) + strlen(table_name)+1)))
3949
3880
    return 1;                                   // End of memory
3971
3902
    char command[80];
3972
3903
    Lex_input_stream *lip= thd->m_lip;
3973
3904
    strmake(command, lip->yylval->symbol.str,
3974
 
            min(lip->yylval->symbol.length, sizeof(command)-1));
 
3905
            min((ulong)lip->yylval->symbol.length, sizeof(command)-1));
3975
3906
    my_error(ER_CANT_USE_OPTION_HERE, MYF(0), command);
3976
3907
    return 1;
3977
3908
  }
4059
3990
*/
4060
3991
 
4061
3992
bool multi_update_precheck(THD *thd,
4062
 
                           TABLE_LIST *tables __attribute__((unused)))
 
3993
                           TableList *tables __attribute__((unused)))
4063
3994
{
4064
3995
  const char *msg= 0;
4065
3996
  LEX *lex= thd->lex;
4096
4027
*/
4097
4028
 
4098
4029
bool multi_delete_precheck(THD *thd,
4099
 
                           TABLE_LIST *tables __attribute__((unused)))
 
4030
                           TableList *tables __attribute__((unused)))
4100
4031
{
4101
4032
  SELECT_LEX *select_lex= &thd->lex->select_lex;
4102
 
  TABLE_LIST **save_query_tables_own_last= thd->lex->query_tables_own_last;
 
4033
  TableList **save_query_tables_own_last= thd->lex->query_tables_own_last;
4103
4034
 
4104
4035
  thd->lex->query_tables_own_last= 0;
4105
4036
  thd->lex->query_tables_own_last= save_query_tables_own_last;
4131
4062
  @return Matching table, NULL otherwise.
4132
4063
*/
4133
4064
 
4134
 
static TABLE_LIST *multi_delete_table_match(LEX *lex __attribute__((unused)),
4135
 
                                            TABLE_LIST *tbl,
4136
 
                                            TABLE_LIST *tables)
 
4065
static TableList *multi_delete_table_match(LEX *lex __attribute__((unused)),
 
4066
                                            TableList *tbl,
 
4067
                                            TableList *tables)
4137
4068
{
4138
 
  TABLE_LIST *match= NULL;
 
4069
  TableList *match= NULL;
4139
4070
 
4140
 
  for (TABLE_LIST *elem= tables; elem; elem= elem->next_local)
 
4071
  for (TableList *elem= tables; elem; elem= elem->next_local)
4141
4072
  {
4142
4073
    int cmp;
4143
4074
 
4185
4116
 
4186
4117
bool multi_delete_set_locks_and_link_aux_tables(LEX *lex)
4187
4118
{
4188
 
  TABLE_LIST *tables= (TABLE_LIST*)lex->select_lex.table_list.first;
4189
 
  TABLE_LIST *target_tbl;
 
4119
  TableList *tables= (TableList*)lex->select_lex.table_list.first;
 
4120
  TableList *target_tbl;
4190
4121
 
4191
4122
  lex->table_count= 0;
4192
4123
 
4193
 
  for (target_tbl= (TABLE_LIST *)lex->auxiliary_table_list.first;
 
4124
  for (target_tbl= (TableList *)lex->auxiliary_table_list.first;
4194
4125
       target_tbl; target_tbl= target_tbl->next_local)
4195
4126
  {
4196
4127
    lex->table_count++;
4197
4128
    /* All tables in aux_tables must be found in FROM PART */
4198
 
    TABLE_LIST *walk= multi_delete_table_match(lex, target_tbl, tables);
 
4129
    TableList *walk= multi_delete_table_match(lex, target_tbl, tables);
4199
4130
    if (!walk)
4200
4131
      return(true);
4201
4132
    if (!walk->derived)
4223
4154
    true  Error
4224
4155
*/
4225
4156
 
4226
 
bool update_precheck(THD *thd, TABLE_LIST *tables __attribute__((unused)))
 
4157
bool update_precheck(THD *thd, TableList *tables __attribute__((unused)))
4227
4158
{
4228
4159
  if (thd->lex->select_lex.item_list.elements != thd->lex->value_list.elements)
4229
4160
  {
4246
4177
    true   error
4247
4178
*/
4248
4179
 
4249
 
bool insert_precheck(THD *thd, TABLE_LIST *tables __attribute__((unused)))
 
4180
bool insert_precheck(THD *thd, TableList *tables __attribute__((unused)))
4250
4181
{
4251
4182
  LEX *lex= thd->lex;
4252
4183
 
4277
4208
*/
4278
4209
 
4279
4210
bool create_table_precheck(THD *thd,
4280
 
                           TABLE_LIST *tables __attribute__((unused)),
4281
 
                           TABLE_LIST *create_table)
 
4211
                           TableList *tables __attribute__((unused)),
 
4212
                           TableList *create_table)
4282
4213
{
4283
4214
  LEX *lex= thd->lex;
4284
4215
  SELECT_LEX *select_lex= &lex->select_lex;
4401
4332
 
4402
4333
 
4403
4334
bool check_string_char_length(LEX_STRING *str, const char *err_msg,
4404
 
                              uint max_char_length, CHARSET_INFO *cs,
 
4335
                              uint max_char_length, const CHARSET_INFO * const cs,
4405
4336
                              bool no_error)
4406
4337
{
4407
4338
  int well_formed_error;
4426
4357
    so they should be prohibited until such support is done.
4427
4358
    This is why we use the 3-byte utf8 to check well-formedness here.
4428
4359
  */
4429
 
  CHARSET_INFO *cs= &my_charset_utf8mb3_general_ci;
 
4360
  const CHARSET_INFO * const cs= &my_charset_utf8mb3_general_ci;
4430
4361
#else
4431
 
  CHARSET_INFO *cs= system_charset_info;
 
4362
  const CHARSET_INFO * const cs= system_charset_info;
4432
4363
#endif
4433
4364
  int well_formed_error;
4434
4365
  uint res= cs->cset->well_formed_len(cs, str->str, str->str + str->length,
4507
4438
 
4508
4439
  @param thd Thread context.
4509
4440
  @param lip Lexer context.
4510
 
  @param creation_ctx Object creation context.
4511
4441
 
4512
4442
  @return Error status.
4513
4443
    @retval false on success.
4514
4444
    @retval true on parsing error.
4515
4445
*/
4516
4446
 
4517
 
bool parse_sql(THD *thd,
4518
 
               Lex_input_stream *lip,
4519
 
               Object_creation_ctx *creation_ctx)
 
4447
bool parse_sql(THD *thd, Lex_input_stream *lip)
4520
4448
{
4521
4449
  assert(thd->m_lip == NULL);
4522
4450
 
4523
 
  /* Backup creation context. */
4524
 
 
4525
 
  Object_creation_ctx *backup_ctx= NULL;
4526
 
 
4527
 
  if (creation_ctx)
4528
 
    backup_ctx= creation_ctx->set_n_backup(thd);
4529
 
 
4530
4451
  /* Set Lex_input_stream. */
4531
4452
 
4532
4453
  thd->m_lip= lip;
4543
4464
 
4544
4465
  thd->m_lip= NULL;
4545
4466
 
4546
 
  /* Restore creation context. */
4547
 
 
4548
 
  if (creation_ctx)
4549
 
    creation_ctx->restore_env(thd, backup_ctx);
4550
 
 
4551
4467
  /* That's it. */
4552
4468
 
4553
4469
  return mysql_parse_status || thd->is_fatal_error;