~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/sql_base.cc

  • Committer: Brian Aker
  • Date: 2008-08-18 22:20:43 UTC
  • mto: This revision was merged to the branch mainline in revision 352.
  • Revision ID: brian@tangent.org-20080818222043-et6zf93ogrgx1cz9
Refactoring table.h

Show diffs side-by-side

added added

removed removed

Lines of Context:
34
34
static pthread_mutex_t LOCK_table_share;
35
35
static bool table_def_inited= 0;
36
36
 
37
 
static int open_unireg_entry(THD *thd, Table *entry, TABLE_LIST *table_list,
 
37
static int open_unireg_entry(THD *thd, Table *entry, TableList *table_list,
38
38
                             const char *alias,
39
39
                             char *cache_key, uint cache_key_length,
40
40
                             MEM_ROOT *mem_root, uint flags);
100
100
    Length of key
101
101
*/
102
102
 
103
 
uint create_table_def_key(THD *thd, char *key, TABLE_LIST *table_list,
 
103
uint create_table_def_key(THD *thd, char *key, TableList *table_list,
104
104
                          bool tmp_table)
105
105
{
106
106
  uint key_length= (uint) (stpcpy(stpcpy(key, table_list->db)+1,
200
200
   #  Share for table
201
201
*/
202
202
 
203
 
TABLE_SHARE *get_table_share(THD *thd, TABLE_LIST *table_list, char *key,
 
203
TABLE_SHARE *get_table_share(THD *thd, TableList *table_list, char *key,
204
204
                             uint key_length, uint db_flags, int *error)
205
205
{
206
206
  TABLE_SHARE *share;
303
303
*/
304
304
 
305
305
static TABLE_SHARE
306
 
*get_table_share_with_create(THD *thd, TABLE_LIST *table_list,
 
306
*get_table_share_with_create(THD *thd, TableList *table_list,
307
307
                             char *key, uint key_length,
308
308
                             uint db_flags, int *error)
309
309
{
431
431
TABLE_SHARE *get_cached_table_share(const char *db, const char *table_name)
432
432
{
433
433
  char key[NAME_LEN*2+2];
434
 
  TABLE_LIST table_list;
 
434
  TableList table_list;
435
435
  uint key_length;
436
436
  safe_mutex_assert_owner(&LOCK_open);
437
437
 
513
513
    #           Pointer to list of names of open tables.
514
514
*/
515
515
 
516
 
OPEN_TABLE_LIST *list_open_tables(THD *thd __attribute__((unused)),
 
516
OPEN_TableList *list_open_tables(THD *thd __attribute__((unused)),
517
517
                                  const char *db, const char *wild)
518
518
{
519
519
  int result = 0;
520
 
  OPEN_TABLE_LIST **start_list, *open_list;
521
 
  TABLE_LIST table_list;
 
520
  OPEN_TableList **start_list, *open_list;
 
521
  TableList table_list;
522
522
 
523
523
  VOID(pthread_mutex_lock(&LOCK_open));
524
524
  memset(&table_list, 0, sizeof(table_list));
527
527
 
528
528
  for (uint idx=0 ; result == 0 && idx < open_cache.records; idx++)
529
529
  {
530
 
    OPEN_TABLE_LIST *table;
 
530
    OPEN_TableList *table;
531
531
    Table *entry=(Table*) hash_element(&open_cache,idx);
532
532
    TABLE_SHARE *share= entry->s;
533
533
 
555
555
    }
556
556
    if (table)
557
557
      continue;
558
 
    if (!(*start_list = (OPEN_TABLE_LIST *)
 
558
    if (!(*start_list = (OPEN_TableList *)
559
559
          sql_alloc(sizeof(**start_list)+share->table_cache_key.length)))
560
560
    {
561
561
      open_list=0;                              // Out of memory
645
645
          and tables must be NULL.
646
646
*/
647
647
 
648
 
bool close_cached_tables(THD *thd, TABLE_LIST *tables, bool have_lock,
 
648
bool close_cached_tables(THD *thd, TableList *tables, bool have_lock,
649
649
                         bool wait_for_refresh, bool wait_for_placeholders)
650
650
{
651
651
  bool result=0;
721
721
  else
722
722
  {
723
723
    bool found=0;
724
 
    for (TABLE_LIST *table= tables; table; table= table->next_local)
 
724
    for (TableList *table= tables; table; table= table->next_local)
725
725
    {
726
726
      if (remove_table_from_cache(thd, table->db, table->table_name,
727
727
                                  RTFC_OWNED_BY_THD_FLAG))
820
820
                                    LEX_STRING *connection, bool have_lock)
821
821
{
822
822
  uint idx;
823
 
  TABLE_LIST tmp, *tables= NULL;
 
823
  TableList tmp, *tables= NULL;
824
824
  bool result= false;
825
825
  assert(thd);
826
826
 
827
 
  memset(&tmp, 0, sizeof(TABLE_LIST));
 
827
  memset(&tmp, 0, sizeof(TableList));
828
828
 
829
829
  if (!have_lock)
830
830
    VOID(pthread_mutex_lock(&LOCK_open));
852
852
    tmp.table_name= share->table_name.str;
853
853
    tmp.next_local= tables;
854
854
 
855
 
    tables= (TABLE_LIST *) memdup_root(thd->mem_root, (char*)&tmp, 
856
 
                                       sizeof(TABLE_LIST));
 
855
    tables= (TableList *) memdup_root(thd->mem_root, (char*)&tmp, 
 
856
                                       sizeof(TableList));
857
857
  }
858
858
 
859
859
  if (tables)
1289
1289
    #           Pointer to found table.
1290
1290
*/
1291
1291
 
1292
 
TABLE_LIST *find_table_in_list(TABLE_LIST *table,
1293
 
                               TABLE_LIST *TABLE_LIST::*link,
 
1292
TableList *find_table_in_list(TableList *table,
 
1293
                               TableList *TableList::*link,
1294
1294
                               const char *db_name,
1295
1295
                               const char *table_name)
1296
1296
{
1329
1329
    Also SELECT::exclude_from_table_unique_test used to exclude from check
1330
1330
    tables of main SELECT of multi-delete and multi-update
1331
1331
 
1332
 
    We also skip tables with TABLE_LIST::prelocking_placeholder set,
 
1332
    We also skip tables with TableList::prelocking_placeholder set,
1333
1333
    because we want to allow SELECTs from them, and their modification
1334
1334
    will rise the error anyway.
1335
1335
 
1341
1341
    0 if table is unique
1342
1342
*/
1343
1343
 
1344
 
TABLE_LIST* unique_table(THD *thd, TABLE_LIST *table, TABLE_LIST *table_list,
 
1344
TableList* unique_table(THD *thd, TableList *table, TableList *table_list,
1345
1345
                         bool check_alias)
1346
1346
{
1347
 
  TABLE_LIST *res;
 
1347
  TableList *res;
1348
1348
  const char *d_name, *t_name, *t_alias;
1349
1349
 
1350
1350
  /*
1351
1351
    If this function called for query which update table (INSERT/UPDATE/...)
1352
1352
    then we have in table->table pointer to Table object which we are
1353
 
    updating even if it is VIEW so we need TABLE_LIST of this Table object
 
1353
    updating even if it is VIEW so we need TableList of this Table object
1354
1354
    to get right names (even if lower_case_table_names used).
1355
1355
 
1356
1356
    If this function called for CREATE command that we have not opened table
1357
 
    (table->table equal to 0) and right names is in current TABLE_LIST
 
1357
    (table->table equal to 0) and right names is in current TableList
1358
1358
    object.
1359
1359
  */
1360
1360
  if (table->table)
1364
1364
      return(0);
1365
1365
    table= table->find_underlying_table(table->table);
1366
1366
    /*
1367
 
      as far as we have table->table we have to find real TABLE_LIST of
 
1367
      as far as we have table->table we have to find real TableList of
1368
1368
      it in underlying tables
1369
1369
    */
1370
1370
    assert(table);
1408
1408
    here we hide view underlying tables if we have them
1409
1409
*/
1410
1410
 
1411
 
void update_non_unique_table_error(TABLE_LIST *update,
 
1411
void update_non_unique_table_error(TableList *update,
1412
1412
                                   const char *operation __attribute__((unused)),
1413
 
                                   TABLE_LIST *duplicate __attribute__((unused)))
 
1413
                                   TableList *duplicate __attribute__((unused)))
1414
1414
{
1415
1415
  my_error(ER_UPDATE_TABLE_USED, MYF(0), update->alias);
1416
1416
}
1418
1418
 
1419
1419
Table *find_temporary_table(THD *thd, const char *db, const char *table_name)
1420
1420
{
1421
 
  TABLE_LIST table_list;
 
1421
  TableList table_list;
1422
1422
 
1423
1423
  table_list.db= (char*) db;
1424
1424
  table_list.table_name= (char*) table_name;
1426
1426
}
1427
1427
 
1428
1428
 
1429
 
Table *find_temporary_table(THD *thd, TABLE_LIST *table_list)
 
1429
Table *find_temporary_table(THD *thd, TableList *table_list)
1430
1430
{
1431
1431
  char  key[MAX_DBKEY_LENGTH];
1432
1432
  uint  key_length;
1469
1469
  @retval -1  the table is in use by a outer query
1470
1470
*/
1471
1471
 
1472
 
int drop_temporary_table(THD *thd, TABLE_LIST *table_list)
 
1472
int drop_temporary_table(THD *thd, TableList *table_list)
1473
1473
{
1474
1474
  Table *table;
1475
1475
 
1573
1573
  char *key;
1574
1574
  uint key_length;
1575
1575
  TABLE_SHARE *share= table->s;
1576
 
  TABLE_LIST table_list;
 
1576
  TableList table_list;
1577
1577
 
1578
1578
  if (!(key=(char*) alloc_root(&share->mem_root, MAX_DBKEY_LENGTH)))
1579
1579
    return(1);                          /* purecov: inspected */
1754
1754
  @return false on success, true otherwise.
1755
1755
*/
1756
1756
 
1757
 
bool name_lock_locked_table(THD *thd, TABLE_LIST *tables)
 
1757
bool name_lock_locked_table(THD *thd, TableList *tables)
1758
1758
{
1759
1759
  /* Under LOCK TABLES we must only accept write locked tables. */
1760
1760
  tables->table= find_locked_table(thd, tables->db, tables->table_name);
1783
1783
  SYNOPSIS
1784
1784
    reopen_name_locked_table()
1785
1785
      thd         Thread handle
1786
 
      table_list  TABLE_LIST object for table to be open, TABLE_LIST::table
 
1786
      table_list  TableList object for table to be open, TableList::table
1787
1787
                  member should point to Table object which was used for
1788
1788
                  name-locking.
1789
1789
      link_in     true  - if Table object for table to be opened should be
1800
1800
    true  - Error
1801
1801
*/
1802
1802
 
1803
 
bool reopen_name_locked_table(THD* thd, TABLE_LIST* table_list, bool link_in)
 
1803
bool reopen_name_locked_table(THD* thd, TableList* table_list, bool link_in)
1804
1804
{
1805
1805
  Table *table= table_list->table;
1806
1806
  TABLE_SHARE *share;
1987
1987
    @retval  false  No error. 'exists' out parameter set accordingly.
1988
1988
*/
1989
1989
 
1990
 
bool check_if_table_exists(THD *thd, TABLE_LIST *table, bool *exists)
 
1990
bool check_if_table_exists(THD *thd, TableList *table, bool *exists)
1991
1991
{
1992
1992
  char path[FN_REFLEN];
1993
1993
  int rc;
2062
2062
*/
2063
2063
 
2064
2064
 
2065
 
Table *open_table(THD *thd, TABLE_LIST *table_list, MEM_ROOT *mem_root,
 
2065
Table *open_table(THD *thd, TableList *table_list, MEM_ROOT *mem_root,
2066
2066
                  bool *refresh, uint flags)
2067
2067
{
2068
2068
  register Table *table;
2519
2519
  bool error= 1;
2520
2520
  Field **field;
2521
2521
  uint key,part;
2522
 
  TABLE_LIST table_list;
 
2522
  TableList table_list;
2523
2523
  THD *thd= table->in_use;
2524
2524
 
2525
2525
  assert(table->s->ref_count == 0);
2530
2530
    sql_print_error(_("Table %s had a open data handler in reopen_table"),
2531
2531
                    table->alias);
2532
2532
#endif
2533
 
  memset(&table_list, 0, sizeof(TABLE_LIST));
 
2533
  memset(&table_list, 0, sizeof(TableList));
2534
2534
  table_list.db=         table->s->db.str;
2535
2535
  table_list.table_name= table->s->table_name.str;
2536
2536
  table_list.table=      table;
3074
3074
    open_unireg_entry()
3075
3075
    thd                 Thread handle
3076
3076
    entry               Store open table definition here
3077
 
    table_list          TABLE_LIST with db, table_name
 
3077
    table_list          TableList with db, table_name
3078
3078
    alias               Alias name
3079
3079
    cache_key           Key for share_cache
3080
3080
    cache_key_length    length of cache_key
3091
3091
    #   Error
3092
3092
*/
3093
3093
 
3094
 
static int open_unireg_entry(THD *thd, Table *entry, TABLE_LIST *table_list,
 
3094
static int open_unireg_entry(THD *thd, Table *entry, TableList *table_list,
3095
3095
                             const char *alias,
3096
3096
                             char *cache_key, uint cache_key_length,
3097
3097
                             MEM_ROOT *mem_root __attribute__((unused)),
3273
3273
    -1 - error
3274
3274
*/
3275
3275
 
3276
 
int open_tables(THD *thd, TABLE_LIST **start, uint *counter, uint flags)
 
3276
int open_tables(THD *thd, TableList **start, uint *counter, uint flags)
3277
3277
{
3278
 
  TABLE_LIST *tables= NULL;
 
3278
  TableList *tables= NULL;
3279
3279
  bool refresh;
3280
3280
  int result=0;
3281
3281
  MEM_ROOT new_frm_mem;
3312
3312
      continue;
3313
3313
    }
3314
3314
    /*
3315
 
      If this TABLE_LIST object is a placeholder for an information_schema
 
3315
      If this TableList object is a placeholder for an information_schema
3316
3316
      table, create a temporary table to represent the information_schema
3317
3317
      table in the query. Do not fill it yet - will be filled during
3318
3318
      execution.
3450
3450
    and locking issues because it does not call lock_tables().
3451
3451
*/
3452
3452
 
3453
 
Table *open_n_lock_single_table(THD *thd, TABLE_LIST *table_l,
 
3453
Table *open_n_lock_single_table(THD *thd, TableList *table_l,
3454
3454
                                thr_lock_type lock_type)
3455
3455
{
3456
 
  TABLE_LIST *save_next_global;
 
3456
  TableList *save_next_global;
3457
3457
 
3458
3458
  /* Remember old 'next' pointer. */
3459
3459
  save_next_global= table_l->next_global;
3498
3498
      table_list->table         table
3499
3499
*/
3500
3500
 
3501
 
Table *open_ltable(THD *thd, TABLE_LIST *table_list, thr_lock_type lock_type,
 
3501
Table *open_ltable(THD *thd, TableList *table_list, thr_lock_type lock_type,
3502
3502
                   uint lock_flags)
3503
3503
{
3504
3504
  Table *table;
3558
3558
    the third argument set appropriately.
3559
3559
*/
3560
3560
 
3561
 
int open_and_lock_tables_derived(THD *thd, TABLE_LIST *tables, bool derived)
 
3561
int open_and_lock_tables_derived(THD *thd, TableList *tables, bool derived)
3562
3562
{
3563
3563
  uint counter;
3564
3564
  bool need_reopen;
3603
3603
    data from the tables.
3604
3604
*/
3605
3605
 
3606
 
bool open_normal_and_derived_tables(THD *thd, TABLE_LIST *tables, uint flags)
 
3606
bool open_normal_and_derived_tables(THD *thd, TableList *tables, uint flags)
3607
3607
{
3608
3608
  uint counter;
3609
3609
  assert(!thd->fill_derived_tables());
3651
3651
   @param tables Tables involved in the query
3652
3652
 */
3653
3653
 
3654
 
int decide_logging_format(THD *thd, TABLE_LIST *tables)
 
3654
int decide_logging_format(THD *thd, TableList *tables)
3655
3655
{
3656
3656
  if (mysql_bin_log.is_open() && (thd->options & OPTION_BIN_LOG))
3657
3657
  {
3659
3659
    handler::Table_flags flags_all_set= ~handler::Table_flags();
3660
3660
    bool multi_engine= false;
3661
3661
    void* prev_ht= NULL;
3662
 
    for (TABLE_LIST *table= tables; table; table= table->next_global)
 
3662
    for (TableList *table= tables; table; table= table->next_global)
3663
3663
    {
3664
3664
      if (!table->placeholder() && table->lock_type >= TL_WRITE_ALLOW_WRITE)
3665
3665
      {
3764
3764
   -1   Error
3765
3765
*/
3766
3766
 
3767
 
int lock_tables(THD *thd, TABLE_LIST *tables, uint count, bool *need_reopen)
 
3767
int lock_tables(THD *thd, TableList *tables, uint count, bool *need_reopen)
3768
3768
{
3769
 
  TABLE_LIST *table;
 
3769
  TableList *table;
3770
3770
 
3771
3771
  /*
3772
3772
    We can't meet statement requiring prelocking if we already
3799
3799
  }
3800
3800
  else
3801
3801
  {
3802
 
    TABLE_LIST *first_not_own= thd->lex->first_not_own_table();
 
3802
    TableList *first_not_own= thd->lex->first_not_own_table();
3803
3803
    /*
3804
3804
      When open_and_lock_tables() is called for a single table out of
3805
3805
      a table list, the 'next_global' chain is temporarily broken. We
3835
3835
 
3836
3836
*/
3837
3837
 
3838
 
void close_tables_for_reopen(THD *thd, TABLE_LIST **tables)
 
3838
void close_tables_for_reopen(THD *thd, TableList **tables)
3839
3839
{
3840
3840
  /*
3841
3841
    If table list consists only from tables from prelocking set, table list
3844
3844
  if (thd->lex->first_not_own_table() == *tables)
3845
3845
    *tables= 0;
3846
3846
  thd->lex->chop_off_not_own_tables();
3847
 
  for (TABLE_LIST *tmp= *tables; tmp; tmp= tmp->next_global)
 
3847
  for (TableList *tmp= *tables; tmp; tmp= tmp->next_global)
3848
3848
    tmp->table= 0;
3849
3849
  close_thread_tables(thd);
3850
3850
}
3878
3878
  TABLE_SHARE *share;
3879
3879
  char cache_key[MAX_DBKEY_LENGTH], *saved_cache_key, *tmp_path;
3880
3880
  uint key_length;
3881
 
  TABLE_LIST table_list;
 
3881
  TableList table_list;
3882
3882
 
3883
3883
  table_list.db=         (char*) db;
3884
3884
  table_list.table_name= (char*) table_name;
4045
4045
*/
4046
4046
 
4047
4047
static Field *
4048
 
find_field_in_view(THD *thd, TABLE_LIST *table_list,
 
4048
find_field_in_view(THD *thd, TableList *table_list,
4049
4049
                   const char *name, uint length __attribute__((unused)),
4050
4050
                   const char *item_name __attribute__((unused)),
4051
4051
                   Item **ref,
4122
4122
*/
4123
4123
 
4124
4124
static Field *
4125
 
find_field_in_natural_join(THD *thd, TABLE_LIST *table_ref, const char *name,
 
4125
find_field_in_natural_join(THD *thd, TableList *table_ref, const char *name,
4126
4126
                           uint length __attribute__((unused)),
4127
4127
                           Item **ref, bool register_tree_change,
4128
 
                           TABLE_LIST **actual_table)
 
4128
                           TableList **actual_table)
4129
4129
{
4130
4130
  List_iterator_fast<Natural_join_column>
4131
4131
    field_it(*(table_ref->join_columns));
4321
4321
*/
4322
4322
 
4323
4323
Field *
4324
 
find_field_in_table_ref(THD *thd, TABLE_LIST *table_list,
 
4324
find_field_in_table_ref(THD *thd, TableList *table_list,
4325
4325
                        const char *name, uint length,
4326
4326
                        const char *item_name, const char *db_name,
4327
4327
                        const char *table_name, Item **ref,
4328
4328
                        bool check_privileges, bool allow_rowid,
4329
4329
                        uint *cached_field_index_ptr,
4330
 
                        bool register_tree_change, TABLE_LIST **actual_table)
 
4330
                        bool register_tree_change, TableList **actual_table)
4331
4331
{
4332
4332
  Field *fld;
4333
4333
 
4395
4395
    */
4396
4396
    if (table_name && table_name[0])
4397
4397
    {
4398
 
      List_iterator<TABLE_LIST> it(table_list->nested_join->join_list);
4399
 
      TABLE_LIST *table;
 
4398
      List_iterator<TableList> it(table_list->nested_join->join_list);
 
4399
      TableList *table;
4400
4400
      while ((table= it++))
4401
4401
      {
4402
4402
        if ((fld= find_field_in_table_ref(thd, table, name, length, item_name,
4537
4537
 
4538
4538
Field *
4539
4539
find_field_in_tables(THD *thd, Item_ident *item,
4540
 
                     TABLE_LIST *first_table, TABLE_LIST *last_table,
 
4540
                     TableList *first_table, TableList *last_table,
4541
4541
                     Item **ref, find_item_error_report_type report_error,
4542
4542
                     bool check_privileges, bool register_tree_change)
4543
4543
{
4547
4547
  const char *name= item->field_name;
4548
4548
  uint length=(uint) strlen(name);
4549
4549
  char name_buff[NAME_LEN+1];
4550
 
  TABLE_LIST *cur_table= first_table;
4551
 
  TABLE_LIST *actual_table;
 
4550
  TableList *cur_table= first_table;
 
4551
  TableList *actual_table;
4552
4552
  bool allow_rowid;
4553
4553
 
4554
4554
  if (!table_name || !table_name[0])
4563
4563
  {
4564
4564
    /*
4565
4565
      This shortcut is used by prepared statements. We assume that
4566
 
      TABLE_LIST *first_table is not changed during query execution (which
 
4566
      TableList *first_table is not changed during query execution (which
4567
4567
      is true for all queries except RENAME but luckily RENAME doesn't
4568
4568
      use fields...) so we can rely on reusing pointer to its member.
4569
4569
      With this optimization we also miss case when addition of one more
4570
4570
      field makes some prepared query ambiguous and so erroneous, but we
4571
4571
      accept this trade off.
4572
4572
    */
4573
 
    TABLE_LIST *table_ref= item->cached_table;
 
4573
    TableList *table_ref= item->cached_table;
4574
4574
    /*
4575
4575
      The condition (table_ref->view == NULL) ensures that we will call
4576
4576
      find_field_in_table even in the case of information schema tables
5030
5030
*/
5031
5031
 
5032
5032
static bool
5033
 
set_new_item_local_context(THD *thd, Item_ident *item, TABLE_LIST *table_ref)
 
5033
set_new_item_local_context(THD *thd, Item_ident *item, TableList *table_ref)
5034
5034
{
5035
5035
  Name_resolution_context *context;
5036
5036
  if (!(context= new (thd->mem_root) Name_resolution_context))
5075
5075
*/
5076
5076
 
5077
5077
static bool
5078
 
mark_common_columns(THD *thd, TABLE_LIST *table_ref_1, TABLE_LIST *table_ref_2,
 
5078
mark_common_columns(THD *thd, TableList *table_ref_1, TableList *table_ref_2,
5079
5079
                    List<String> *using_fields, uint *found_using_fields)
5080
5080
{
5081
5081
  Field_iterator_table_ref it_1, it_2;
5086
5086
    Leaf table references to which new natural join columns are added
5087
5087
    if the leaves are != NULL.
5088
5088
  */
5089
 
  TABLE_LIST *leaf_1= (table_ref_1->nested_join &&
 
5089
  TableList *leaf_1= (table_ref_1->nested_join &&
5090
5090
                       !table_ref_1->is_natural_join) ?
5091
5091
                      NULL : table_ref_1;
5092
 
  TABLE_LIST *leaf_2= (table_ref_2->nested_join &&
 
5092
  TableList *leaf_2= (table_ref_2->nested_join &&
5093
5093
                       !table_ref_2->is_natural_join) ?
5094
5094
                      NULL : table_ref_2;
5095
5095
 
5290
5290
 
5291
5291
static bool
5292
5292
store_natural_using_join_columns(THD *thd __attribute__((unused)),
5293
 
                                 TABLE_LIST *natural_using_join,
5294
 
                                 TABLE_LIST *table_ref_1,
5295
 
                                 TABLE_LIST *table_ref_2,
 
5293
                                 TableList *natural_using_join,
 
5294
                                 TableList *table_ref_1,
 
5295
                                 TableList *table_ref_2,
5296
5296
                                 List<String> *using_fields,
5297
5297
                                 uint found_using_fields)
5298
5298
{
5392
5392
  DESCRIPTION
5393
5393
    The procedure performs a post-order traversal of a nested join tree
5394
5394
    and materializes the row types of NATURAL/USING joins in a
5395
 
    bottom-up manner until it reaches the TABLE_LIST elements that
 
5395
    bottom-up manner until it reaches the TableList elements that
5396
5396
    represent the top-most NATURAL/USING joins. The procedure should be
5397
5397
    applied to each element of SELECT_LEX::top_join_list (i.e. to each
5398
5398
    top-level element of the FROM clause).
5408
5408
*/
5409
5409
 
5410
5410
static bool
5411
 
store_top_level_join_columns(THD *thd, TABLE_LIST *table_ref,
5412
 
                             TABLE_LIST *left_neighbor,
5413
 
                             TABLE_LIST *right_neighbor)
 
5411
store_top_level_join_columns(THD *thd, TableList *table_ref,
 
5412
                             TableList *left_neighbor,
 
5413
                             TableList *right_neighbor)
5414
5414
{
5415
5415
  bool result= true;
5416
5416
 
5417
5417
  /* Call the procedure recursively for each nested table reference. */
5418
5418
  if (table_ref->nested_join)
5419
5419
  {
5420
 
    List_iterator_fast<TABLE_LIST> nested_it(table_ref->nested_join->join_list);
5421
 
    TABLE_LIST *same_level_left_neighbor= nested_it++;
5422
 
    TABLE_LIST *same_level_right_neighbor= NULL;
 
5420
    List_iterator_fast<TableList> nested_it(table_ref->nested_join->join_list);
 
5421
    TableList *same_level_left_neighbor= nested_it++;
 
5422
    TableList *same_level_right_neighbor= NULL;
5423
5423
    /* Left/right-most neighbors, possibly at higher levels in the join tree. */
5424
 
    TABLE_LIST *real_left_neighbor, *real_right_neighbor;
 
5424
    TableList *real_left_neighbor, *real_right_neighbor;
5425
5425
 
5426
5426
    while (same_level_left_neighbor)
5427
5427
    {
5428
 
      TABLE_LIST *cur_table_ref= same_level_left_neighbor;
 
5428
      TableList *cur_table_ref= same_level_left_neighbor;
5429
5429
      same_level_left_neighbor= nested_it++;
5430
5430
      /*
5431
5431
        The order of RIGHT JOIN operands is reversed in 'join list' to
5443
5443
      {
5444
5444
        /* This can happen only for JOIN ... ON. */
5445
5445
        assert(table_ref->nested_join->join_list.elements == 2);
5446
 
        swap_variables(TABLE_LIST*, same_level_left_neighbor, cur_table_ref);
 
5446
        swap_variables(TableList*, same_level_left_neighbor, cur_table_ref);
5447
5447
      }
5448
5448
 
5449
5449
      /*
5471
5471
  {
5472
5472
    assert(table_ref->nested_join &&
5473
5473
                table_ref->nested_join->join_list.elements == 2);
5474
 
    List_iterator_fast<TABLE_LIST> operand_it(table_ref->nested_join->join_list);
 
5474
    List_iterator_fast<TableList> operand_it(table_ref->nested_join->join_list);
5475
5475
    /*
5476
5476
      Notice that the order of join operands depends on whether table_ref
5477
5477
      represents a LEFT or a RIGHT join. In a RIGHT join, the operands are
5478
5478
      in inverted order.
5479
5479
     */
5480
 
    TABLE_LIST *table_ref_2= operand_it++; /* Second NATURAL join operand.*/
5481
 
    TABLE_LIST *table_ref_1= operand_it++; /* First NATURAL join operand. */
 
5480
    TableList *table_ref_2= operand_it++; /* Second NATURAL join operand.*/
 
5481
    TableList *table_ref_1= operand_it++; /* First NATURAL join operand. */
5482
5482
    List<String> *using_fields= table_ref->join_using_fields;
5483
5483
    uint found_using_fields;
5484
5484
 
5487
5487
      back for 'mark_common_columns'.
5488
5488
    */
5489
5489
    if (table_ref_2->outer_join & JOIN_TYPE_RIGHT)
5490
 
      swap_variables(TABLE_LIST*, table_ref_1, table_ref_2);
 
5490
      swap_variables(TableList*, table_ref_1, table_ref_2);
5491
5491
    if (mark_common_columns(thd, table_ref_1, table_ref_2,
5492
5492
                            using_fields, &found_using_fields))
5493
5493
      goto err;
5498
5498
      same as of an equivalent LEFT JOIN.
5499
5499
    */
5500
5500
    if (table_ref_1->outer_join & JOIN_TYPE_RIGHT)
5501
 
      swap_variables(TABLE_LIST*, table_ref_1, table_ref_2);
 
5501
      swap_variables(TableList*, table_ref_1, table_ref_2);
5502
5502
    if (store_natural_using_join_columns(thd, table_ref, table_ref_1,
5503
5503
                                         table_ref_2, using_fields,
5504
5504
                                         found_using_fields))
5520
5520
    /* Change this table reference to become a leaf for name resolution. */
5521
5521
    if (left_neighbor)
5522
5522
    {
5523
 
      TABLE_LIST *last_leaf_on_the_left;
 
5523
      TableList *last_leaf_on_the_left;
5524
5524
      last_leaf_on_the_left= left_neighbor->last_leaf_for_name_resolution();
5525
5525
      last_leaf_on_the_left->next_name_resolution_table= table_ref;
5526
5526
    }
5527
5527
    if (right_neighbor)
5528
5528
    {
5529
 
      TABLE_LIST *first_leaf_on_the_right;
 
5529
      TableList *first_leaf_on_the_right;
5530
5530
      first_leaf_on_the_right= right_neighbor->first_leaf_for_name_resolution();
5531
5531
      table_ref->next_name_resolution_table= first_leaf_on_the_right;
5532
5532
    }
5565
5565
    false  OK
5566
5566
*/
5567
5567
static bool setup_natural_join_row_types(THD *thd,
5568
 
                                         List<TABLE_LIST> *from_clause,
 
5568
                                         List<TableList> *from_clause,
5569
5569
                                         Name_resolution_context *context)
5570
5570
{
5571
5571
  thd->where= "from clause";
5572
5572
  if (from_clause->elements == 0)
5573
5573
    return false; /* We come here in the case of UNIONs. */
5574
5574
 
5575
 
  List_iterator_fast<TABLE_LIST> table_ref_it(*from_clause);
5576
 
  TABLE_LIST *table_ref; /* Current table reference. */
 
5575
  List_iterator_fast<TableList> table_ref_it(*from_clause);
 
5576
  TableList *table_ref; /* Current table reference. */
5577
5577
  /* Table reference to the left of the current. */
5578
 
  TABLE_LIST *left_neighbor;
 
5578
  TableList *left_neighbor;
5579
5579
  /* Table reference to the right of the current. */
5580
 
  TABLE_LIST *right_neighbor= NULL;
 
5580
  TableList *right_neighbor= NULL;
5581
5581
 
5582
5582
  /* Note that tables in the list are in reversed order */
5583
5583
  for (left_neighbor= table_ref_it++; left_neighbor ; )
5592
5592
        return true;
5593
5593
      if (left_neighbor)
5594
5594
      {
5595
 
        TABLE_LIST *first_leaf_on_the_right;
 
5595
        TableList *first_leaf_on_the_right;
5596
5596
        first_leaf_on_the_right= table_ref->first_leaf_for_name_resolution();
5597
5597
        left_neighbor->next_name_resolution_table= first_leaf_on_the_right;
5598
5598
      }
5619
5619
****************************************************************************/
5620
5620
 
5621
5621
int setup_wild(THD *thd,
5622
 
               TABLE_LIST *tables __attribute__((unused)),
 
5622
               TableList *tables __attribute__((unused)),
5623
5623
               List<Item> &fields,
5624
5624
               List<Item> *sum_func_list,
5625
5625
               uint wild_num)
5751
5751
  RETURN pointer on pointer to next_leaf of last element
5752
5752
*/
5753
5753
 
5754
 
TABLE_LIST **make_leaves_list(TABLE_LIST **list, TABLE_LIST *tables)
 
5754
TableList **make_leaves_list(TableList **list, TableList *tables)
5755
5755
{
5756
 
  for (TABLE_LIST *table= tables; table; table= table->next_local)
 
5756
  for (TableList *table= tables; table; table= table->next_local)
5757
5757
  {
5758
5758
    {
5759
5759
      *list= table;
5792
5792
*/
5793
5793
 
5794
5794
bool setup_tables(THD *thd, Name_resolution_context *context,
5795
 
                  List<TABLE_LIST> *from_clause, TABLE_LIST *tables,
5796
 
                  TABLE_LIST **leaves, bool select_insert)
 
5795
                  List<TableList> *from_clause, TableList *tables,
 
5796
                  TableList **leaves, bool select_insert)
5797
5797
{
5798
5798
  uint tablenr= 0;
5799
5799
 
5803
5803
    this is used for INSERT ... SELECT.
5804
5804
    For select we setup tables except first (and its underlying tables)
5805
5805
  */
5806
 
  TABLE_LIST *first_select_table= (select_insert ?
 
5806
  TableList *first_select_table= (select_insert ?
5807
5807
                                   tables->next_local:
5808
5808
                                   0);
5809
5809
  if (!(*leaves))
5810
5810
    make_leaves_list(leaves, tables);
5811
5811
 
5812
 
  TABLE_LIST *table_list;
 
5812
  TableList *table_list;
5813
5813
  for (table_list= *leaves;
5814
5814
       table_list;
5815
5815
       table_list= table_list->next_leaf, tablenr++)
5866
5866
*/
5867
5867
bool setup_tables_and_check_access(THD *thd, 
5868
5868
                                   Name_resolution_context *context,
5869
 
                                   List<TABLE_LIST> *from_clause,
5870
 
                                   TABLE_LIST *tables,
5871
 
                                   TABLE_LIST **leaves,
 
5869
                                   List<TableList> *from_clause,
 
5870
                                   TableList *tables,
 
5871
                                   TableList **leaves,
5872
5872
                                   bool select_insert)
5873
5873
{
5874
 
  TABLE_LIST *leaves_tmp= NULL;
 
5874
  TableList *leaves_tmp= NULL;
5875
5875
  bool first_table= true;
5876
5876
 
5877
5877
  if (setup_tables(thd, context, from_clause, tables,
5975
5975
    else treat natural joins as leaves and do not iterate over their underlying
5976
5976
    tables.
5977
5977
  */
5978
 
  for (TABLE_LIST *tables= (table_name ? context->table_list :
 
5978
  for (TableList *tables= (table_name ? context->table_list :
5979
5979
                            context->first_name_resolution_table);
5980
5980
       tables;
5981
5981
       tables= (table_name ? tables->next_local :
6099
6099
    false if all is OK
6100
6100
*/
6101
6101
 
6102
 
int setup_conds(THD *thd, TABLE_LIST *tables __attribute__((unused)),
6103
 
                TABLE_LIST *leaves,
 
6102
int setup_conds(THD *thd, TableList *tables __attribute__((unused)),
 
6103
                TableList *leaves,
6104
6104
                COND **conds)
6105
6105
{
6106
6106
  SELECT_LEX *select_lex= thd->lex->current_select;
6107
 
  TABLE_LIST *table= NULL;      // For HP compilers
 
6107
  TableList *table= NULL;       // For HP compilers
6108
6108
  void *save_thd_marker= thd->thd_marker;
6109
6109
  /*
6110
6110
    it_is_update set to true when tables of primary SELECT_LEX (SELECT_LEX
6138
6138
  */
6139
6139
  for (table= leaves; table; table= table->next_leaf)
6140
6140
  {
6141
 
    TABLE_LIST *embedded; /* The table at the current level of nesting. */
6142
 
    TABLE_LIST *embedding= table; /* The parent nested table reference. */
 
6141
    TableList *embedded; /* The table at the current level of nesting. */
 
6142
    TableList *embedding= table; /* The parent nested table reference. */
6143
6143
    do
6144
6144
    {
6145
6145
      embedded= embedding;