~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/sql_base.cc

  • Committer: Brian Aker
  • Date: 2008-10-20 03:40:03 UTC
  • mto: (492.3.21 drizzle-clean-code)
  • mto: This revision was merged to the branch mainline in revision 530.
  • Revision ID: brian@tangent.org-20081020034003-t2dcnl0ayr2ymm8k
THD -> Session rename

Show diffs side-by-side

added added

removed removed

Lines of Context:
53
53
static pthread_mutex_t LOCK_table_share;
54
54
static bool table_def_inited= 0;
55
55
 
56
 
static int open_unireg_entry(THD *thd, Table *entry, TableList *table_list,
 
56
static int open_unireg_entry(Session *thd, Table *entry, TableList *table_list,
57
57
                             const char *alias,
58
58
                             char *cache_key, uint32_t cache_key_length);
59
59
static void free_cache_entry(Table *entry);
60
 
static void close_old_data_files(THD *thd, Table *table, bool morph_locks,
 
60
static void close_old_data_files(Session *thd, Table *table, bool morph_locks,
61
61
                                 bool send_refresh);
62
62
 
63
63
 
118
118
    Length of key
119
119
*/
120
120
 
121
 
uint32_t create_table_def_key(THD *thd, char *key, TableList *table_list,
 
121
uint32_t create_table_def_key(Session *thd, char *key, TableList *table_list,
122
122
                          bool tmp_table)
123
123
{
124
124
  uint32_t key_length= (uint) (my_stpcpy(my_stpcpy(key, table_list->db)+1,
218
218
   #  Share for table
219
219
*/
220
220
 
221
 
TABLE_SHARE *get_table_share(THD *thd, TableList *table_list, char *key,
 
221
TABLE_SHARE *get_table_share(Session *thd, TableList *table_list, char *key,
222
222
                             uint32_t key_length, uint32_t db_flags, int *error)
223
223
{
224
224
  TABLE_SHARE *share;
321
321
*/
322
322
 
323
323
static TABLE_SHARE
324
 
*get_table_share_with_create(THD *thd, TableList *table_list,
 
324
*get_table_share_with_create(Session *thd, TableList *table_list,
325
325
                             char *key, uint32_t key_length,
326
326
                             uint32_t db_flags, int *error)
327
327
{
455
455
 
456
456
  table_list.db= (char*) db;
457
457
  table_list.table_name= (char*) table_name;
458
 
  key_length= create_table_def_key((THD*) 0, key, &table_list, 0);
 
458
  key_length= create_table_def_key((Session*) 0, key, &table_list, 0);
459
459
  return (TABLE_SHARE*) hash_search(&table_def_cache,(unsigned char*) key, key_length);
460
460
}  
461
461
 
518
518
 
519
519
  SYNOPSIS
520
520
    list_open_tables()
521
 
    thd                 Thread THD
 
521
    thd                 Thread Session
522
522
    wild                SQL like expression
523
523
 
524
524
  NOTES
531
531
    #           Pointer to list of names of open tables.
532
532
*/
533
533
 
534
 
OPEN_TableList *list_open_tables(THD *thd __attribute__((unused)),
 
534
OPEN_TableList *list_open_tables(Session *thd __attribute__((unused)),
535
535
                                  const char *db, const char *wild)
536
536
{
537
537
  int result = 0;
659
659
         won't proceed while write-locked tables are being reopened by other
660
660
         threads.
661
661
 
662
 
  @remark THD can be NULL, but then wait_for_refresh must be false
 
662
  @remark Session can be NULL, but then wait_for_refresh must be false
663
663
          and tables must be NULL.
664
664
*/
665
665
 
666
 
bool close_cached_tables(THD *thd, TableList *tables, bool have_lock,
 
666
bool close_cached_tables(Session *thd, TableList *tables, bool have_lock,
667
667
                         bool wait_for_refresh, bool wait_for_placeholders)
668
668
{
669
669
  bool result=0;
742
742
    for (TableList *table= tables; table; table= table->next_local)
743
743
    {
744
744
      if (remove_table_from_cache(thd, table->db, table->table_name,
745
 
                                  RTFC_OWNED_BY_THD_FLAG))
 
745
                                  RTFC_OWNED_BY_Session_FLAG))
746
746
        found=1;
747
747
    }
748
748
    if (!found)
834
834
  if specified string is NULL, then any table with a connection string.
835
835
*/
836
836
 
837
 
bool close_cached_connection_tables(THD *thd, bool if_wait_for_refresh,
 
837
bool close_cached_connection_tables(Session *thd, bool if_wait_for_refresh,
838
838
                                    LEX_STRING *connection, bool have_lock)
839
839
{
840
840
  uint32_t idx;
903
903
          is not reset until the HANDLER is closed.
904
904
*/
905
905
 
906
 
static void mark_temp_tables_as_free_for_reuse(THD *thd)
 
906
static void mark_temp_tables_as_free_for_reuse(Session *thd)
907
907
{
908
908
  for (Table *table= thd->temporary_tables ; table ; table= table->next)
909
909
  {
939
939
    set to query_id of original query.
940
940
*/
941
941
 
942
 
static void mark_used_tables_as_free_for_reuse(THD *thd, Table *table)
 
942
static void mark_used_tables_as_free_for_reuse(Session *thd, Table *table)
943
943
{
944
944
  for (; table ; table= table->next)
945
945
  {
960
960
  @remark It should not ordinarily be called directly.
961
961
*/
962
962
 
963
 
static void close_open_tables(THD *thd)
 
963
static void close_open_tables(Session *thd)
964
964
{
965
965
  bool found_old_table= 0;
966
966
 
1003
1003
    leave prelocked mode if needed.
1004
1004
*/
1005
1005
 
1006
 
void close_thread_tables(THD *thd)
 
1006
void close_thread_tables(Session *thd)
1007
1007
{
1008
1008
  Table *table;
1009
1009
 
1096
1096
 
1097
1097
/* move one table to free list */
1098
1098
 
1099
 
bool close_thread_table(THD *thd, Table **table_ptr)
 
1099
bool close_thread_table(Session *thd, Table **table_ptr)
1100
1100
{
1101
1101
  bool found_old_table= 0;
1102
1102
  Table *table= *table_ptr;
1138
1138
 
1139
1139
 
1140
1140
/* close_temporary_tables' internal, 4 is due to uint4korr definition */
1141
 
static inline uint32_t  tmpkeyval(THD *thd __attribute__((unused)),
 
1141
static inline uint32_t  tmpkeyval(Session *thd __attribute__((unused)),
1142
1142
                              Table *table)
1143
1143
{
1144
1144
  return uint4korr(table->s->table_cache_key.str + table->s->table_cache_key.length - 4);
1150
1150
  creates one DROP TEMPORARY Table binlog event for each pseudo-thread 
1151
1151
*/
1152
1152
 
1153
 
void close_temporary_tables(THD *thd)
 
1153
void close_temporary_tables(Session *thd)
1154
1154
{
1155
1155
  Table *table;
1156
1156
  Table *next= NULL;
1334
1334
    check_alias           whether to check tables' aliases
1335
1335
 
1336
1336
  NOTE: to exclude derived tables from check we use following mechanism:
1337
 
    a) during derived table processing set THD::derived_tables_processing
 
1337
    a) during derived table processing set Session::derived_tables_processing
1338
1338
    b) JOIN::prepare set SELECT::exclude_from_table_unique_test if
1339
 
       THD::derived_tables_processing set. (we can't use JOIN::execute
 
1339
       Session::derived_tables_processing set. (we can't use JOIN::execute
1340
1340
       because for PS we perform only JOIN::prepare, but we can't set this
1341
1341
       flag in JOIN::prepare if we are not sure that we are in derived table
1342
1342
       processing loop, because multi-update call fix_fields() for some its
1359
1359
    0 if table is unique
1360
1360
*/
1361
1361
 
1362
 
TableList* unique_table(THD *thd, TableList *table, TableList *table_list,
 
1362
TableList* unique_table(Session *thd, TableList *table, TableList *table_list,
1363
1363
                         bool check_alias)
1364
1364
{
1365
1365
  TableList *res;
1434
1434
}
1435
1435
 
1436
1436
 
1437
 
Table *find_temporary_table(THD *thd, const char *db, const char *table_name)
 
1437
Table *find_temporary_table(Session *thd, const char *db, const char *table_name)
1438
1438
{
1439
1439
  TableList table_list;
1440
1440
 
1444
1444
}
1445
1445
 
1446
1446
 
1447
 
Table *find_temporary_table(THD *thd, TableList *table_list)
 
1447
Table *find_temporary_table(Session *thd, TableList *table_list)
1448
1448
{
1449
1449
  char  key[MAX_DBKEY_LENGTH];
1450
1450
  uint  key_length;
1487
1487
  @retval -1  the table is in use by a outer query
1488
1488
*/
1489
1489
 
1490
 
int drop_temporary_table(THD *thd, TableList *table_list)
 
1490
int drop_temporary_table(Session *thd, TableList *table_list)
1491
1491
{
1492
1492
  Table *table;
1493
1493
 
1514
1514
  unlink from thd->temporary tables and close temporary table
1515
1515
*/
1516
1516
 
1517
 
void close_temporary_table(THD *thd, Table *table,
 
1517
void close_temporary_table(Session *thd, Table *table,
1518
1518
                           bool free_share, bool delete_table)
1519
1519
{
1520
1520
  if (table->prev)
1585
1585
  thd->slave_proxy_id, separated by '\0'.
1586
1586
*/
1587
1587
 
1588
 
bool rename_temporary_table(THD* thd, Table *table, const char *db,
 
1588
bool rename_temporary_table(Session* thd, Table *table, const char *db,
1589
1589
                            const char *table_name)
1590
1590
{
1591
1591
  char *key;
1636
1636
          not locked (for example already unlocked).
1637
1637
*/
1638
1638
 
1639
 
void unlink_open_table(THD *thd, Table *find, bool unlock)
 
1639
void unlink_open_table(Session *thd, Table *find, bool unlock)
1640
1640
{
1641
1641
  char key[MAX_DBKEY_LENGTH];
1642
1642
  uint32_t key_length= find->s->table_cache_key.length;
1699
1699
          table that was locked with LOCK TABLES.
1700
1700
*/
1701
1701
 
1702
 
void drop_open_table(THD *thd, Table *table, const char *db_name,
 
1702
void drop_open_table(Session *thd, Table *table, const char *db_name,
1703
1703
                     const char *table_name)
1704
1704
{
1705
1705
  if (table->s->tmp_table)
1730
1730
     cond       Condition to wait for
1731
1731
*/
1732
1732
 
1733
 
void wait_for_condition(THD *thd, pthread_mutex_t *mutex, pthread_cond_t *cond)
 
1733
void wait_for_condition(Session *thd, pthread_mutex_t *mutex, pthread_cond_t *cond)
1734
1734
{
1735
1735
  /* Wait until the current table is up to date */
1736
1736
  const char *proc_info;
1772
1772
  @return false on success, true otherwise.
1773
1773
*/
1774
1774
 
1775
 
bool name_lock_locked_table(THD *thd, TableList *tables)
 
1775
bool name_lock_locked_table(Session *thd, TableList *tables)
1776
1776
{
1777
1777
  /* Under LOCK TABLES we must only accept write locked tables. */
1778
1778
  tables->table= find_locked_table(thd, tables->db, tables->table_name);
1805
1805
                  member should point to Table object which was used for
1806
1806
                  name-locking.
1807
1807
      link_in     true  - if Table object for table to be opened should be
1808
 
                          linked into THD::open_tables list.
 
1808
                          linked into Session::open_tables list.
1809
1809
                  false - placeholder used for name-locking is already in
1810
1810
                          this list so we only need to preserve Table::next
1811
1811
                          pointer.
1818
1818
    true  - Error
1819
1819
*/
1820
1820
 
1821
 
bool reopen_name_locked_table(THD* thd, TableList* table_list, bool link_in)
 
1821
bool reopen_name_locked_table(Session* thd, TableList* table_list, bool link_in)
1822
1822
{
1823
1823
  Table *table= table_list->table;
1824
1824
  TABLE_SHARE *share;
1867
1867
  else
1868
1868
  {
1869
1869
    /*
1870
 
      Table object should be already in THD::open_tables list so we just
 
1870
      Table object should be already in Session::open_tables list so we just
1871
1871
      need to set Table::next correctly.
1872
1872
    */
1873
1873
    table->next= orig_table.next;
1897
1897
            case of failure.
1898
1898
*/
1899
1899
 
1900
 
Table *table_cache_insert_placeholder(THD *thd, const char *key,
 
1900
Table *table_cache_insert_placeholder(Session *thd, const char *key,
1901
1901
                                      uint32_t key_length)
1902
1902
{
1903
1903
  Table *table;
1956
1956
    @retval  false  Success. 'table' parameter set according to above rules.
1957
1957
*/
1958
1958
 
1959
 
bool lock_table_name_if_not_cached(THD *thd, const char *db,
 
1959
bool lock_table_name_if_not_cached(Session *thd, const char *db,
1960
1960
                                   const char *table_name, Table **table)
1961
1961
{
1962
1962
  char key[MAX_DBKEY_LENGTH];
2005
2005
    @retval  false  No error. 'exists' out parameter set accordingly.
2006
2006
*/
2007
2007
 
2008
 
bool check_if_table_exists(THD *thd, TableList *table, bool *exists)
 
2008
bool check_if_table_exists(Session *thd, TableList *table, bool *exists)
2009
2009
{
2010
2010
  char path[FN_REFLEN];
2011
2011
  int rc;
2080
2080
*/
2081
2081
 
2082
2082
 
2083
 
Table *open_table(THD *thd, TableList *table_list, bool *refresh, uint32_t flags)
 
2083
Table *open_table(Session *thd, TableList *table_list, bool *refresh, uint32_t flags)
2084
2084
{
2085
2085
  register Table *table;
2086
2086
  char key[MAX_DBKEY_LENGTH];
2123
2123
        /*
2124
2124
          We're trying to use the same temporary table twice in a query.
2125
2125
          Right now we don't support this because a temporary table
2126
 
          is always represented by only one Table object in THD, and
 
2126
          is always represented by only one Table object in Session, and
2127
2127
          it can not be cloned. Emit an error for an unsupported behaviour.
2128
2128
        */
2129
2129
        if (table->query_id)
2498
2498
}
2499
2499
 
2500
2500
 
2501
 
Table *find_locked_table(THD *thd, const char *db,const char *table_name)
 
2501
Table *find_locked_table(Session *thd, const char *db,const char *table_name)
2502
2502
{
2503
2503
  char  key[MAX_DBKEY_LENGTH];
2504
2504
  uint32_t key_length=(uint) (my_stpcpy(my_stpcpy(key,db)+1,table_name)-key)+1;
2536
2536
  Field **field;
2537
2537
  uint32_t key,part;
2538
2538
  TableList table_list;
2539
 
  THD *thd= table->in_use;
 
2539
  Session *thd= table->in_use;
2540
2540
 
2541
2541
  assert(table->s->ref_count == 0);
2542
2542
  assert(!table->sort.io_cache);
2627
2627
          the strings are used in a loop even after the share may be freed.
2628
2628
*/
2629
2629
 
2630
 
void close_data_files_and_morph_locks(THD *thd, const char *db,
 
2630
void close_data_files_and_morph_locks(Session *thd, const char *db,
2631
2631
                                      const char *table_name)
2632
2632
{
2633
2633
  Table *table;
2686
2686
    @return false in case of success, true - otherwise.
2687
2687
*/
2688
2688
 
2689
 
bool reopen_tables(THD *thd, bool get_locks, bool mark_share_as_old)
 
2689
bool reopen_tables(Session *thd, bool get_locks, bool mark_share_as_old)
2690
2690
{
2691
2691
  Table *table,*next,**prev;
2692
2692
  Table **tables,**tables_ptr;                  // For locks
2788
2788
    @param send_refresh  Should we awake waiters even if we didn't close any tables?
2789
2789
*/
2790
2790
 
2791
 
static void close_old_data_files(THD *thd, Table *table, bool morph_locks,
 
2791
static void close_old_data_files(Session *thd, Table *table, bool morph_locks,
2792
2792
                                 bool send_refresh)
2793
2793
{
2794
2794
  bool found= send_refresh;
2900
2900
 
2901
2901
/* Wait until all used tables are refreshed */
2902
2902
 
2903
 
bool wait_for_tables(THD *thd)
 
2903
bool wait_for_tables(Session *thd)
2904
2904
{
2905
2905
  bool result;
2906
2906
 
2954
2954
*/
2955
2955
 
2956
2956
 
2957
 
Table *drop_locked_tables(THD *thd,const char *db, const char *table_name)
 
2957
Table *drop_locked_tables(Session *thd,const char *db, const char *table_name)
2958
2958
{
2959
2959
  Table *table,*next,**prev, *found= 0;
2960
2960
  prev= &thd->open_tables;
3014
3014
  other threads trying to get the lock.
3015
3015
*/
3016
3016
 
3017
 
void abort_locked_tables(THD *thd,const char *db, const char *table_name)
 
3017
void abort_locked_tables(Session *thd,const char *db, const char *table_name)
3018
3018
{
3019
3019
  Table *table;
3020
3020
  for (table= thd->open_tables; table ; table= table->next)
3103
3103
    #   Error
3104
3104
*/
3105
3105
 
3106
 
static int open_unireg_entry(THD *thd, Table *entry, TableList *table_list,
 
3106
static int open_unireg_entry(Session *thd, Table *entry, TableList *table_list,
3107
3107
                             const char *alias,
3108
3108
                             char *cache_key, uint32_t cache_key_length)
3109
3109
{
3226
3226
        /* this DELETE FROM is needed even with row-based binlogging */
3227
3227
        end = strxmov(my_stpcpy(query, "DELETE FROM `"),
3228
3228
                      share->db.str,"`.`",share->table_name.str,"`", NULL);
3229
 
        thd->binlog_query(THD::STMT_QUERY_TYPE,
 
3229
        thd->binlog_query(Session::STMT_QUERY_TYPE,
3230
3230
                          query, (ulong)(end-query), false, false);
3231
3231
        free(query);
3232
3232
      }
3281
3281
    -1 - error
3282
3282
*/
3283
3283
 
3284
 
int open_tables(THD *thd, TableList **start, uint32_t *counter, uint32_t flags)
 
3284
int open_tables(Session *thd, TableList **start, uint32_t *counter, uint32_t flags)
3285
3285
{
3286
3286
  TableList *tables= NULL;
3287
3287
  bool refresh;
3408
3408
  1     error
3409
3409
*/
3410
3410
 
3411
 
static bool check_lock_and_start_stmt(THD *thd, Table *table,
 
3411
static bool check_lock_and_start_stmt(Session *thd, Table *table,
3412
3412
                                      thr_lock_type lock_type)
3413
3413
{
3414
3414
  int error;
3458
3458
    and locking issues because it does not call lock_tables().
3459
3459
*/
3460
3460
 
3461
 
Table *open_n_lock_single_table(THD *thd, TableList *table_l,
 
3461
Table *open_n_lock_single_table(Session *thd, TableList *table_l,
3462
3462
                                thr_lock_type lock_type)
3463
3463
{
3464
3464
  TableList *save_next_global;
3506
3506
      table_list->table         table
3507
3507
*/
3508
3508
 
3509
 
Table *open_ltable(THD *thd, TableList *table_list, thr_lock_type lock_type,
 
3509
Table *open_ltable(Session *thd, TableList *table_list, thr_lock_type lock_type,
3510
3510
                   uint32_t lock_flags)
3511
3511
{
3512
3512
  Table *table;
3566
3566
    the third argument set appropriately.
3567
3567
*/
3568
3568
 
3569
 
int open_and_lock_tables_derived(THD *thd, TableList *tables, bool derived)
 
3569
int open_and_lock_tables_derived(Session *thd, TableList *tables, bool derived)
3570
3570
{
3571
3571
  uint32_t counter;
3572
3572
  bool need_reopen;
3611
3611
    data from the tables.
3612
3612
*/
3613
3613
 
3614
 
bool open_normal_and_derived_tables(THD *thd, TableList *tables, uint32_t flags)
 
3614
bool open_normal_and_derived_tables(Session *thd, TableList *tables, uint32_t flags)
3615
3615
{
3616
3616
  uint32_t counter;
3617
3617
  assert(!thd->fill_derived_tables());
3659
3659
   @param tables Tables involved in the query
3660
3660
 */
3661
3661
 
3662
 
int decide_logging_format(THD *thd, TableList *tables)
 
3662
int decide_logging_format(Session *thd, TableList *tables)
3663
3663
{
3664
3664
  if (mysql_bin_log.is_open() && (thd->options & OPTION_BIN_LOG))
3665
3665
  {
3756
3756
   -1   Error
3757
3757
*/
3758
3758
 
3759
 
int lock_tables(THD *thd, TableList *tables, uint32_t count, bool *need_reopen)
 
3759
int lock_tables(Session *thd, TableList *tables, uint32_t count, bool *need_reopen)
3760
3760
{
3761
3761
  TableList *table;
3762
3762
 
3827
3827
 
3828
3828
*/
3829
3829
 
3830
 
void close_tables_for_reopen(THD *thd, TableList **tables)
 
3830
void close_tables_for_reopen(Session *thd, TableList **tables)
3831
3831
{
3832
3832
  /*
3833
3833
    If table list consists only from tables from prelocking set, table list
3862
3862
   #  Table object
3863
3863
*/
3864
3864
 
3865
 
Table *open_temporary_table(THD *thd, const char *path, const char *db,
 
3865
Table *open_temporary_table(Session *thd, const char *path, const char *db,
3866
3866
                            const char *table_name, bool link_in_list,
3867
3867
                            open_table_mode open_mode)
3868
3868
{
3973
3973
 
3974
3974
#define WRONG_GRANT (Field*) -1
3975
3975
 
3976
 
static void update_field_dependencies(THD *thd, Field *field, Table *table)
 
3976
static void update_field_dependencies(Session *thd, Field *field, Table *table)
3977
3977
{
3978
3978
  if (thd->mark_used_columns != MARK_COLUMNS_NONE)
3979
3979
  {
4044
4044
*/
4045
4045
 
4046
4046
static Field *
4047
 
find_field_in_natural_join(THD *thd, TableList *table_ref, const char *name,
 
4047
find_field_in_natural_join(Session *thd, TableList *table_ref, const char *name,
4048
4048
                           uint32_t length __attribute__((unused)),
4049
4049
                           Item **ref __attribute__((unused)), bool register_tree_change __attribute__((unused)),
4050
4050
                           TableList **actual_table)
4104
4104
*/
4105
4105
 
4106
4106
Field *
4107
 
find_field_in_table(THD *thd, Table *table, const char *name, uint32_t length,
 
4107
find_field_in_table(Session *thd, Table *table, const char *name, uint32_t length,
4108
4108
                    bool allow_rowid, uint32_t *cached_field_index_ptr)
4109
4109
{
4110
4110
  Field **field_ptr, *field;
4217
4217
*/
4218
4218
 
4219
4219
Field *
4220
 
find_field_in_table_ref(THD *thd, TableList *table_list,
 
4220
find_field_in_table_ref(Session *thd, TableList *table_list,
4221
4221
                        const char *name, uint32_t length,
4222
4222
                        const char *item_name, const char *db_name,
4223
4223
                        const char *table_name, Item **ref,
4428
4428
*/
4429
4429
 
4430
4430
Field *
4431
 
find_field_in_tables(THD *thd, Item_ident *item,
 
4431
find_field_in_tables(Session *thd, Item_ident *item,
4432
4432
                     TableList *first_table, TableList *last_table,
4433
4433
                     Item **ref, find_item_error_report_type report_error,
4434
4434
                     bool check_privileges, bool register_tree_change)
4922
4922
*/
4923
4923
 
4924
4924
static bool
4925
 
set_new_item_local_context(THD *thd, Item_ident *item, TableList *table_ref)
 
4925
set_new_item_local_context(Session *thd, Item_ident *item, TableList *table_ref)
4926
4926
{
4927
4927
  Name_resolution_context *context;
4928
4928
  if (!(context= new (thd->mem_root) Name_resolution_context))
4967
4967
*/
4968
4968
 
4969
4969
static bool
4970
 
mark_common_columns(THD *thd, TableList *table_ref_1, TableList *table_ref_2,
 
4970
mark_common_columns(Session *thd, TableList *table_ref_1, TableList *table_ref_2,
4971
4971
                    List<String> *using_fields, uint32_t *found_using_fields)
4972
4972
{
4973
4973
  Field_iterator_table_ref it_1, it_2;
5181
5181
*/
5182
5182
 
5183
5183
static bool
5184
 
store_natural_using_join_columns(THD *thd __attribute__((unused)),
 
5184
store_natural_using_join_columns(Session *thd __attribute__((unused)),
5185
5185
                                 TableList *natural_using_join,
5186
5186
                                 TableList *table_ref_1,
5187
5187
                                 TableList *table_ref_2,
5300
5300
*/
5301
5301
 
5302
5302
static bool
5303
 
store_top_level_join_columns(THD *thd, TableList *table_ref,
 
5303
store_top_level_join_columns(Session *thd, TableList *table_ref,
5304
5304
                             TableList *left_neighbor,
5305
5305
                             TableList *right_neighbor)
5306
5306
{
5456
5456
    true   Error
5457
5457
    false  OK
5458
5458
*/
5459
 
static bool setup_natural_join_row_types(THD *thd,
 
5459
static bool setup_natural_join_row_types(Session *thd,
5460
5460
                                         List<TableList> *from_clause,
5461
5461
                                         Name_resolution_context *context)
5462
5462
{
5506
5506
** Expand all '*' in given fields
5507
5507
****************************************************************************/
5508
5508
 
5509
 
int setup_wild(THD *thd,
 
5509
int setup_wild(Session *thd,
5510
5510
               TableList *tables __attribute__((unused)),
5511
5511
               List<Item> &fields,
5512
5512
               List<Item> *sum_func_list,
5569
5569
** Check that all given fields exists and fill struct with current data
5570
5570
****************************************************************************/
5571
5571
 
5572
 
bool setup_fields(THD *thd, Item **ref_pointer_array,
 
5572
bool setup_fields(Session *thd, Item **ref_pointer_array,
5573
5573
                  List<Item> &fields, enum_mark_columns mark_used_columns,
5574
5574
                  List<Item> *sum_func_list, bool allow_sum_func)
5575
5575
{
5582
5582
  thd->mark_used_columns= mark_used_columns;
5583
5583
  if (allow_sum_func)
5584
5584
    thd->lex->allow_sum_func|= 1 << thd->lex->current_select->nest_level;
5585
 
  thd->where= THD::DEFAULT_WHERE;
 
5585
  thd->where= Session::DEFAULT_WHERE;
5586
5586
  save_is_item_list_lookup= thd->lex->current_select->is_item_list_lookup;
5587
5587
  thd->lex->current_select->is_item_list_lookup= 0;
5588
5588
 
5679
5679
    true  error
5680
5680
*/
5681
5681
 
5682
 
bool setup_tables(THD *thd, Name_resolution_context *context,
 
5682
bool setup_tables(Session *thd, Name_resolution_context *context,
5683
5683
                  List<TableList> *from_clause, TableList *tables,
5684
5684
                  TableList **leaves, bool select_insert)
5685
5685
{
5752
5752
    false ok;  In this case *map will include the chosen index
5753
5753
    true  error
5754
5754
*/
5755
 
bool setup_tables_and_check_access(THD *thd, 
 
5755
bool setup_tables_and_check_access(Session *thd, 
5756
5756
                                   Name_resolution_context *context,
5757
5757
                                   List<TableList> *from_clause,
5758
5758
                                   TableList *tables,
5836
5836
*/
5837
5837
 
5838
5838
bool
5839
 
insert_fields(THD *thd, Name_resolution_context *context, const char *db_name,
 
5839
insert_fields(Session *thd, Name_resolution_context *context, const char *db_name,
5840
5840
              const char *table_name, List_iterator<Item> *it,
5841
5841
              bool any_privileges __attribute__((unused)))
5842
5842
{
5998
5998
    false if all is OK
5999
5999
*/
6000
6000
 
6001
 
int setup_conds(THD *thd, TableList *tables __attribute__((unused)),
 
6001
int setup_conds(Session *thd, TableList *tables __attribute__((unused)),
6002
6002
                TableList *leaves,
6003
6003
                COND **conds)
6004
6004
{
6096
6096
*/
6097
6097
 
6098
6098
bool
6099
 
fill_record(THD * thd, List<Item> &fields, List<Item> &values, bool ignore_errors)
 
6099
fill_record(Session * thd, List<Item> &fields, List<Item> &values, bool ignore_errors)
6100
6100
{
6101
6101
  List_iterator_fast<Item> f(fields),v(values);
6102
6102
  Item *value, *fld;
6211
6211
*/
6212
6212
 
6213
6213
bool
6214
 
fill_record(THD *thd, Field **ptr, List<Item> &values,
 
6214
fill_record(Session *thd, Field **ptr, List<Item> &values,
6215
6215
            bool ignore_errors __attribute__((unused)))
6216
6216
{
6217
6217
  List_iterator_fast<Item> v(values);
6300
6300
  MY_DIR *dirp;
6301
6301
  FILEINFO *file;
6302
6302
  TABLE_SHARE share;
6303
 
  THD *thd;
 
6303
  Session *thd;
6304
6304
 
6305
 
  if (!(thd= new THD))
 
6305
  if (!(thd= new Session))
6306
6306
    return(1);
6307
6307
  thd->thread_stack= (char*) &thd;
6308
6308
  thd->store_globals();
6359
6359
    my_dirend(dirp);
6360
6360
  }
6361
6361
  delete thd;
6362
 
  pthread_setspecific(THR_THD,  0);
 
6362
  pthread_setspecific(THR_Session,  0);
6363
6363
  return(0);
6364
6364
}
6365
6365
 
6431
6431
    1  Table is in use by another thread
6432
6432
*/
6433
6433
 
6434
 
bool remove_table_from_cache(THD *thd, const char *db, const char *table_name,
 
6434
bool remove_table_from_cache(Session *thd, const char *db, const char *table_name,
6435
6435
                             uint32_t flags)
6436
6436
{
6437
6437
  char key[MAX_DBKEY_LENGTH];
6452
6452
         table= (Table*) hash_next(&open_cache, (unsigned char*) key, key_length,
6453
6453
                                   &state))
6454
6454
    {
6455
 
      THD *in_use;
 
6455
      Session *in_use;
6456
6456
 
6457
6457
      table->s->version=0L;             /* Free when thread is ready */
6458
6458
      if (!(in_use=table->in_use))
6490
6490
        }
6491
6491
      }
6492
6492
      else
6493
 
        result= result || (flags & RTFC_OWNED_BY_THD_FLAG);
 
6493
        result= result || (flags & RTFC_OWNED_BY_Session_FLAG);
6494
6494
    }
6495
6495
    while (unused_tables && !unused_tables->s->version)
6496
6496
      hash_delete(&open_cache,(unsigned char*) unused_tables);