~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to sql/sql_base.cc

  • Committer: Monty Taylor
  • Date: 2008-07-09 16:42:25 UTC
  • mto: (77.6.1 glibclient-merge)
  • mto: This revision was merged to the branch mainline in revision 112.
  • Revision ID: monty@inaugust.com-20080709164225-2r6n4j98nhxh031l
Moved test to tests... 

Show diffs side-by-side

added added

removed removed

Lines of Context:
65
65
  DBUG_ENTER("table_cache_free");
66
66
  if (table_def_inited)
67
67
  {
68
 
    close_cached_tables(NULL, NULL, FALSE, FALSE, FALSE);
 
68
    close_cached_tables(NULL, NULL, false, false, false);
69
69
    if (!open_cache.records)                    // Safety first
70
70
      hash_free(&open_cache);
71
71
  }
466
466
     that the table is deleted or the thread is killed.
467
467
*/
468
468
 
469
 
void release_table_share(TABLE_SHARE *share, enum release_type type)
 
469
void release_table_share(TABLE_SHARE *share,
 
470
                         enum release_type type __attribute__((__unused__)))
470
471
{
471
472
  bool to_be_deleted= 0;
472
473
  DBUG_ENTER("release_table_share");
609
610
    #           Pointer to list of names of open tables.
610
611
*/
611
612
 
612
 
OPEN_TABLE_LIST *list_open_tables(THD *thd, const char *db, const char *wild)
 
613
OPEN_TABLE_LIST *list_open_tables(THD *thd __attribute__((__unused__)),
 
614
                                  const char *db, const char *wild)
613
615
{
614
616
  int result = 0;
615
617
  OPEN_TABLE_LIST **start_list, *open_list;
747
749
         won't proceed while write-locked tables are being reopened by other
748
750
         threads.
749
751
 
750
 
  @remark THD can be NULL, but then wait_for_refresh must be FALSE
 
752
  @remark THD can be NULL, but then wait_for_refresh must be false
751
753
          and tables must be NULL.
752
754
*/
753
755
 
933
935
{
934
936
  uint idx;
935
937
  TABLE_LIST tmp, *tables= NULL;
936
 
  bool result= FALSE;
 
938
  bool result= false;
937
939
  DBUG_ENTER("close_cached_connections");
938
940
  DBUG_ASSERT(thd);
939
941
 
970
972
  }
971
973
 
972
974
  if (tables)
973
 
    result= close_cached_tables(thd, tables, TRUE, FALSE, FALSE);
 
975
    result= close_cached_tables(thd, tables, true, false, false);
974
976
 
975
977
  if (!have_lock)
976
978
    VOID(pthread_mutex_unlock(&LOCK_open));
1146
1148
   */
1147
1149
  if (!(thd->state_flags & Open_tables_state::BACKUPS_AVAIL))
1148
1150
  {
1149
 
    thd->main_da.can_overwrite_status= TRUE;
 
1151
    thd->main_da.can_overwrite_status= true;
1150
1152
    ha_autocommit_or_rollback(thd, thd->is_error());
1151
 
    thd->main_da.can_overwrite_status= FALSE;
 
1153
    thd->main_da.can_overwrite_status= false;
1152
1154
    thd->transaction.stmt.reset();
1153
1155
  }
1154
1156
 
1175
1177
      handled either before writing a query log event (inside
1176
1178
      binlog_query()) or when preparing a pending event.
1177
1179
     */
1178
 
    thd->binlog_flush_pending_rows_event(TRUE);
 
1180
    thd->binlog_flush_pending_rows_event(true);
1179
1181
    mysql_unlock_tables(thd, thd->lock);
1180
1182
    thd->lock=0;
1181
1183
  }
1239
1241
 
1240
1242
 
1241
1243
/* close_temporary_tables' internal, 4 is due to uint4korr definition */
1242
 
static inline uint  tmpkeyval(THD *thd, TABLE *table)
 
1244
static inline uint  tmpkeyval(THD *thd __attribute__((__unused__)),
 
1245
                              TABLE *table)
1243
1246
{
1244
1247
  return uint4korr(table->s->table_cache_key.str + table->s->table_cache_key.length - 4);
1245
1248
}
1256
1259
  TABLE *next= NULL;
1257
1260
  TABLE *prev_table;
1258
1261
  /* Assume thd->options has OPTION_QUOTE_SHOW_CREATE */
1259
 
  bool was_quote_show= TRUE;
 
1262
  bool was_quote_show= true;
1260
1263
 
1261
1264
  if (!thd->temporary_tables)
1262
1265
    return;
1278
1281
  uint stub_len= sizeof(stub) - 1;
1279
1282
  char buf[256];
1280
1283
  String s_query= String(buf, sizeof(buf), system_charset_info);
1281
 
  bool found_user_tables= FALSE;
 
1284
  bool found_user_tables= false;
1282
1285
 
1283
1286
  memcpy(buf, stub, stub_len);
1284
1287
 
1361
1364
      thd->variables.character_set_client= system_charset_info;
1362
1365
      Query_log_event qinfo(thd, s_query.ptr(),
1363
1366
                            s_query.length() - 1 /* to remove trailing ',' */,
1364
 
                            0, FALSE);
 
1367
                            0, false);
1365
1368
      thd->variables.character_set_client= cs_save;
1366
1369
      /*
1367
1370
        Imagine the thread had created a temp table, then was doing a
1532
1535
*/
1533
1536
 
1534
1537
void update_non_unique_table_error(TABLE_LIST *update,
1535
 
                                   const char *operation,
1536
 
                                   TABLE_LIST *duplicate)
 
1538
                                   const char *operation __attribute__((__unused__)),
 
1539
                                   TABLE_LIST *duplicate __attribute__((__unused__)))
1537
1540
{
1538
1541
  my_error(ER_UPDATE_TABLE_USED, MYF(0), update->alias);
1539
1542
}
1622
1625
    If LOCK TABLES list is not empty and contains this table,
1623
1626
    unlock the table and remove the table from this list.
1624
1627
  */
1625
 
  mysql_lock_remove(thd, thd->locked_tables, table, FALSE);
 
1628
  mysql_lock_remove(thd, thd->locked_tables, table, false);
1626
1629
  close_temporary_table(thd, table, 1, 1);
1627
1630
  DBUG_RETURN(0);
1628
1631
}
1754
1757
 
1755
1758
    @param  thd     Thread context
1756
1759
    @param  find    Table to remove
1757
 
    @param  unlock  TRUE  - free all locks on tables removed that are
 
1760
    @param  unlock  true  - free all locks on tables removed that are
1758
1761
                            done with LOCK TABLES
1759
 
                    FALSE - otherwise
 
1762
                    false - otherwise
1760
1763
 
1761
 
    @note When unlock parameter is FALSE or current thread doesn't have
 
1764
    @note When unlock parameter is false or current thread doesn't have
1762
1765
          any tables locked with LOCK TABLES, tables are assumed to be
1763
1766
          not locked (for example already unlocked).
1764
1767
*/
1788
1791
        !memcmp(list->s->table_cache_key.str, key, key_length))
1789
1792
    {
1790
1793
      if (unlock && thd->locked_tables)
1791
 
        mysql_lock_remove(thd, thd->locked_tables, list, TRUE);
 
1794
        mysql_lock_remove(thd, thd->locked_tables, list, true);
1792
1795
 
1793
1796
      /* Remove table from open_tables list. */
1794
1797
      *prev= list->next;
1840
1843
      unlink_open_table() also tells threads waiting for refresh or close
1841
1844
      that something has happened.
1842
1845
    */
1843
 
    unlink_open_table(thd, table, FALSE);
 
1846
    unlink_open_table(thd, table, false);
1844
1847
    quick_rm_table(table_type, db_name, table_name, 0);
1845
1848
    VOID(pthread_mutex_unlock(&LOCK_open));
1846
1849
  }
1898
1901
  @param thd current thread context
1899
1902
  @param tables table list containing one table to open.
1900
1903
 
1901
 
  @return FALSE on success, TRUE otherwise.
 
1904
  @return false on success, true otherwise.
1902
1905
*/
1903
1906
 
1904
1907
bool name_lock_locked_table(THD *thd, TABLE_LIST *tables)
1919
1922
      other statement will open this table.
1920
1923
    */
1921
1924
    wait_while_table_is_used(thd, tables->table, HA_EXTRA_FORCE_REOPEN);
1922
 
    DBUG_RETURN(FALSE);
 
1925
    DBUG_RETURN(false);
1923
1926
  }
1924
1927
 
1925
 
  DBUG_RETURN(TRUE);
 
1928
  DBUG_RETURN(true);
1926
1929
}
1927
1930
 
1928
1931
 
1935
1938
      table_list  TABLE_LIST object for table to be open, TABLE_LIST::table
1936
1939
                  member should point to TABLE object which was used for
1937
1940
                  name-locking.
1938
 
      link_in     TRUE  - if TABLE object for table to be opened should be
 
1941
      link_in     true  - if TABLE object for table to be opened should be
1939
1942
                          linked into THD::open_tables list.
1940
 
                  FALSE - placeholder used for name-locking is already in
 
1943
                  false - placeholder used for name-locking is already in
1941
1944
                          this list so we only need to preserve TABLE::next
1942
1945
                          pointer.
1943
1946
 
1945
1948
    This function assumes that its caller already acquired LOCK_open mutex.
1946
1949
 
1947
1950
  RETURN VALUE
1948
 
    FALSE - Success
1949
 
    TRUE  - Error
 
1951
    false - Success
 
1952
    true  - Error
1950
1953
*/
1951
1954
 
1952
1955
bool reopen_name_locked_table(THD* thd, TABLE_LIST* table_list, bool link_in)
1960
1963
  safe_mutex_assert_owner(&LOCK_open);
1961
1964
 
1962
1965
  if (thd->killed || !table)
1963
 
    DBUG_RETURN(TRUE);
 
1966
    DBUG_RETURN(true);
1964
1967
 
1965
1968
  orig_table= *table;
1966
1969
 
1976
1979
      object to its original state.
1977
1980
    */
1978
1981
    *table= orig_table;
1979
 
    DBUG_RETURN(TRUE);
 
1982
    DBUG_RETURN(true);
1980
1983
  }
1981
1984
 
1982
1985
  share= table->s;
2011
2014
  table->const_table=0;
2012
2015
  table->null_row= table->maybe_null= table->force_index= 0;
2013
2016
  table->status=STATUS_NO_RECORD;
2014
 
  DBUG_RETURN(FALSE);
 
2017
  DBUG_RETURN(false);
2015
2018
}
2016
2019
 
2017
2020
 
2084
2087
          'table' parameter can be set to NULL for some situations when
2085
2088
          table does not really exist.
2086
2089
 
2087
 
    @retval  TRUE   Error occured (OOM)
2088
 
    @retval  FALSE  Success. 'table' parameter set according to above rules.
 
2090
    @retval  true   Error occured (OOM)
 
2091
    @retval  false  Success. 'table' parameter set according to above rules.
2089
2092
*/
2090
2093
 
2091
2094
bool lock_table_name_if_not_cached(THD *thd, const char *db,
2103
2106
    VOID(pthread_mutex_unlock(&LOCK_open));
2104
2107
    DBUG_PRINT("info", ("Table is cached, name-lock is not obtained"));
2105
2108
    *table= 0;
2106
 
    DBUG_RETURN(FALSE);
 
2109
    DBUG_RETURN(false);
2107
2110
  }
2108
2111
  if (!(*table= table_cache_insert_placeholder(thd, key, key_length)))
2109
2112
  {
2110
2113
    VOID(pthread_mutex_unlock(&LOCK_open));
2111
 
    DBUG_RETURN(TRUE);
 
2114
    DBUG_RETURN(true);
2112
2115
  }
2113
2116
  (*table)->open_placeholder= 1;
2114
2117
  (*table)->next= thd->open_tables;
2115
2118
  thd->open_tables= *table;
2116
2119
  VOID(pthread_mutex_unlock(&LOCK_open));
2117
 
  DBUG_RETURN(FALSE);
 
2120
  DBUG_RETURN(false);
2118
2121
}
2119
2122
 
2120
2123
 
2124
2127
 
2125
2128
    @param       thd     Thread context
2126
2129
    @param       table   Table list element
2127
 
    @param[out]  exists  Out parameter which is set to TRUE if table
2128
 
                         exists and to FALSE otherwise.
 
2130
    @param[out]  exists  Out parameter which is set to true if table
 
2131
                         exists and to false otherwise.
2129
2132
 
2130
2133
    @note This function assumes that caller owns LOCK_open mutex.
2131
2134
          It also assumes that the fact that there are no name-locks
2135
2138
          of engines (e.g. it was created on another node of NDB cluster)
2136
2139
          this function will fetch and create proper .FRM file for it.
2137
2140
 
2138
 
    @retval  TRUE   Some error occured
2139
 
    @retval  FALSE  No error. 'exists' out parameter set accordingly.
 
2141
    @retval  true   Some error occured
 
2142
    @retval  false  No error. 'exists' out parameter set accordingly.
2140
2143
*/
2141
2144
 
2142
2145
bool check_if_table_exists(THD *thd, TABLE_LIST *table, bool *exists)
2147
2150
 
2148
2151
  safe_mutex_assert_owner(&LOCK_open);
2149
2152
 
2150
 
  *exists= TRUE;
 
2153
  *exists= true;
2151
2154
 
2152
2155
  if (get_cached_table_share(table->db, table->table_name))
2153
 
    DBUG_RETURN(FALSE);
 
2156
    DBUG_RETURN(false);
2154
2157
 
2155
2158
  build_table_filename(path, sizeof(path) - 1, table->db, table->table_name,
2156
2159
                       reg_ext, 0);
2157
2160
 
2158
2161
  if (!access(path, F_OK))
2159
 
    DBUG_RETURN(FALSE);
 
2162
    DBUG_RETURN(false);
2160
2163
 
2161
2164
  /* .FRM file doesn't exist. Check if some engine can provide it. */
2162
2165
 
2165
2168
  if (rc < 0)
2166
2169
  {
2167
2170
    /* Table does not exists in engines as well. */
2168
 
    *exists= FALSE;
2169
 
    DBUG_RETURN(FALSE);
 
2171
    *exists= false;
 
2172
    DBUG_RETURN(false);
2170
2173
  }
2171
2174
  else if (!rc)
2172
2175
  {
2173
2176
    /* Table exists in some engine and .FRM for it was created. */
2174
 
    DBUG_RETURN(FALSE);
 
2177
    DBUG_RETURN(false);
2175
2178
  }
2176
2179
  else /* (rc > 0) */
2177
2180
  {
2178
2181
    my_printf_error(ER_UNKNOWN_ERROR, "Failed to open '%-.64s', error while "
2179
2182
                    "unpacking from engine", MYF(0), table->table_name);
2180
 
    DBUG_RETURN(TRUE);
 
2183
    DBUG_RETURN(true);
2181
2184
  }
2182
2185
}
2183
2186
 
2273
2276
          DBUG_RETURN(0);
2274
2277
        }
2275
2278
        table->query_id= thd->query_id;
2276
 
        thd->thread_specific_used= TRUE;
 
2279
        thd->thread_specific_used= true;
2277
2280
        DBUG_PRINT("info",("Using temporary table"));
2278
2281
        goto reset;
2279
2282
      }
2646
2649
  table->file->ft_handler= 0;
2647
2650
  /* Catch wrong handling of the auto_increment_field_not_null. */
2648
2651
  DBUG_ASSERT(!table->auto_increment_field_not_null);
2649
 
  table->auto_increment_field_not_null= FALSE;
 
2652
  table->auto_increment_field_not_null= false;
2650
2653
  if (table->timestamp_field)
2651
2654
    table->timestamp_field_type= table->timestamp_field->get_auto_set_type();
2652
2655
  table->pos_in_table_list= table_list;
2819
2822
    {
2820
2823
      if (thd->locked_tables)
2821
2824
      {
2822
 
        mysql_lock_remove(thd, thd->locked_tables, table, TRUE);
 
2825
        mysql_lock_remove(thd, thd->locked_tables, table, true);
2823
2826
      }
2824
2827
      table->open_placeholder= 1;
2825
2828
      close_handle_and_leave_table_as_lock(table);
2846
2849
 
2847
2850
    @note One should have lock on LOCK_open when calling this.
2848
2851
 
2849
 
    @return FALSE in case of success, TRUE - otherwise.
 
2852
    @return false in case of success, true - otherwise.
2850
2853
*/
2851
2854
 
2852
2855
bool reopen_tables(THD *thd, bool get_locks, bool mark_share_as_old)
2948
2951
 
2949
2952
    @param thd           Thread context
2950
2953
    @param table         Head of the list of TABLE objects
2951
 
    @param morph_locks   TRUE  - remove locks which we have on tables being closed
 
2954
    @param morph_locks   true  - remove locks which we have on tables being closed
2952
2955
                                 but ensure that no DML or DDL will sneak in before
2953
2956
                                 we will re-open the table (i.e. temporarily morph
2954
2957
                                 our table-level locks into name-locks).
2955
 
                         FALSE - otherwise
 
2958
                         false - otherwise
2956
2959
    @param send_refresh  Should we awake waiters even if we didn't close any tables?
2957
2960
*/
2958
2961
 
2988
2991
              lock on it. This will also give them a chance to close their
2989
2992
              instances of this table.
2990
2993
            */
2991
 
            mysql_lock_abort(thd, ulcktbl, TRUE);
2992
 
            mysql_lock_remove(thd, thd->locked_tables, ulcktbl, TRUE);
 
2994
            mysql_lock_abort(thd, ulcktbl, true);
 
2995
            mysql_lock_remove(thd, thd->locked_tables, ulcktbl, true);
2993
2996
            ulcktbl->lock_count= 0;
2994
2997
          }
2995
2998
          if ((ulcktbl != table) && ulcktbl->db_stat)
3157
3160
    if (!strcmp(table->s->table_name.str, table_name) &&
3158
3161
        !strcmp(table->s->db.str, db))
3159
3162
    {
3160
 
      mysql_lock_remove(thd, thd->locked_tables, table, TRUE);
 
3163
      mysql_lock_remove(thd, thd->locked_tables, table, true);
3161
3164
 
3162
3165
      if (!found)
3163
3166
      {
3208
3211
        !strcmp(table->s->db.str, db))
3209
3212
    {
3210
3213
      /* If MERGE child, forward lock handling to parent. */
3211
 
      mysql_lock_abort(thd, table, TRUE);
 
3214
      mysql_lock_abort(thd, table, true);
3212
3215
      break;
3213
3216
    }
3214
3217
  }
3297
3300
static int open_unireg_entry(THD *thd, TABLE *entry, TABLE_LIST *table_list,
3298
3301
                             const char *alias,
3299
3302
                             char *cache_key, uint cache_key_length,
3300
 
                             MEM_ROOT *mem_root, uint flags)
 
3303
                             MEM_ROOT *mem_root __attribute__((__unused__)),
 
3304
                             uint flags __attribute__((__unused__)))
3301
3305
{
3302
3306
  int error;
3303
3307
  TABLE_SHARE *share;
3364
3368
    if (!entry->s || !entry->s->crashed)
3365
3369
      goto err;
3366
3370
     // Code below is for repairing a crashed file
3367
 
     if ((error= lock_table_name(thd, table_list, TRUE)))
 
3371
     if ((error= lock_table_name(thd, table_list, true)))
3368
3372
     {
3369
3373
       if (error < 0)
3370
3374
        goto err;
3422
3426
        end = strxmov(strmov(query, "DELETE FROM `"),
3423
3427
                      share->db.str,"`.`",share->table_name.str,"`", NullS);
3424
3428
        thd->binlog_query(THD::STMT_QUERY_TYPE,
3425
 
                          query, (ulong)(end-query), FALSE, FALSE);
 
3429
                          query, (ulong)(end-query), false, false);
3426
3430
        my_free(query, MYF(0));
3427
3431
      }
3428
3432
      else
3506
3510
    DBUG_PRINT("tcache", ("opening table: '%s'.'%s'  item: 0x%lx",
3507
3511
                          tables->db, tables->table_name, (long) tables));
3508
3512
 
3509
 
    safe_to_ignore_table= FALSE;
 
3513
    safe_to_ignore_table= false;
3510
3514
 
3511
3515
    /*
3512
3516
      Ignore placeholders for derived tables. After derived tables
3772
3776
    derived     - if to handle derived tables
3773
3777
 
3774
3778
  RETURN
3775
 
    FALSE - ok
3776
 
    TRUE  - error
 
3779
    false - ok
 
3780
    true  - error
3777
3781
 
3778
3782
  NOTE
3779
3783
    The lock will automaticaly be freed by close_thread_tables()
3814
3818
      (mysql_handle_derived(thd->lex, &mysql_derived_prepare) ||
3815
3819
       (thd->fill_derived_tables() &&
3816
3820
        mysql_handle_derived(thd->lex, &mysql_derived_filling))))
3817
 
    DBUG_RETURN(TRUE); /* purecov: inspected */
 
3821
    DBUG_RETURN(true); /* purecov: inspected */
3818
3822
  DBUG_RETURN(0);
3819
3823
}
3820
3824
 
3831
3835
                  done a flush or namelock on it.
3832
3836
 
3833
3837
  RETURN
3834
 
    FALSE - ok
3835
 
    TRUE  - error
 
3838
    false - ok
 
3839
    true  - error
3836
3840
 
3837
3841
  NOTE 
3838
3842
    This is to be used on prepare stage when you don't read any
3846
3850
  DBUG_ASSERT(!thd->fill_derived_tables());
3847
3851
  if (open_tables(thd, &tables, &counter, flags) ||
3848
3852
      mysql_handle_derived(thd->lex, &mysql_derived_prepare))
3849
 
    DBUG_RETURN(TRUE); /* purecov: inspected */
 
3853
    DBUG_RETURN(true); /* purecov: inspected */
3850
3854
  DBUG_RETURN(0);
3851
3855
}
3852
3856
 
3894
3898
  {
3895
3899
    handler::Table_flags flags_some_set= handler::Table_flags();
3896
3900
    handler::Table_flags flags_all_set= ~handler::Table_flags();
3897
 
    my_bool multi_engine= FALSE;
 
3901
    my_bool multi_engine= false;
3898
3902
    void* prev_ht= NULL;
3899
3903
    for (TABLE_LIST *table= tables; table; table= table->next_global)
3900
3904
    {
3906
3910
                            FLAGSTR(flags, HA_BINLOG_STMT_CAPABLE),
3907
3911
                            FLAGSTR(flags, HA_BINLOG_ROW_CAPABLE)));
3908
3912
        if (prev_ht && prev_ht != table->table->file->ht)
3909
 
          multi_engine= TRUE;
 
3913
          multi_engine= true;
3910
3914
        prev_ht= table->table->file->ht;
3911
3915
        flags_all_set &= flags;
3912
3916
        flags_some_set |= flags;
3922
3926
    DBUG_PRINT("info", ("thd->variables.binlog_format: %ld",
3923
3927
                        thd->variables.binlog_format));
3924
3928
    DBUG_PRINT("info", ("multi_engine: %s",
3925
 
                        multi_engine ? "TRUE" : "FALSE"));
 
3929
                        multi_engine ? "true" : "false"));
3926
3930
 
3927
3931
    int error= 0;
3928
3932
    if (flags_all_set == 0)
3998
4002
    thd                 Thread handler
3999
4003
    tables              Tables to lock
4000
4004
    count               Number of opened tables
4001
 
    need_reopen         Out parameter which if TRUE indicates that some
 
4005
    need_reopen         Out parameter which if true indicates that some
4002
4006
                        tables were dropped or altered during this call
4003
4007
                        and therefore invoker should reopen tables and
4004
4008
                        try to lock them once again (in this case
4027
4031
    We can't meet statement requiring prelocking if we already
4028
4032
    in prelocked mode.
4029
4033
  */
4030
 
  *need_reopen= FALSE;
 
4034
  *need_reopen= false;
4031
4035
 
4032
4036
  if (!tables)
4033
4037
    DBUG_RETURN(decide_logging_format(thd, tables));
4307
4311
    item_name                   name of item if it will be created (VIEW)
4308
4312
    ref                         expression substituted in VIEW should be passed
4309
4313
                                using this reference (return view_ref_found)
4310
 
    register_tree_change        TRUE if ref is not stack variable and we
 
4314
    register_tree_change        true if ref is not stack variable and we
4311
4315
                                need register changes in item tree
4312
4316
 
4313
4317
  RETURN
4318
4322
 
4319
4323
static Field *
4320
4324
find_field_in_view(THD *thd, TABLE_LIST *table_list,
4321
 
                   const char *name, uint length,
4322
 
                   const char *item_name, Item **ref,
4323
 
                   bool register_tree_change)
 
4325
                   const char *name, uint length __attribute__((__unused__)),
 
4326
                   const char *item_name __attribute__((__unused__)),
 
4327
                   Item **ref,
 
4328
                   bool register_tree_change __attribute__((__unused__)))
4324
4329
{
4325
4330
  DBUG_ENTER("find_field_in_view");
4326
4331
  DBUG_PRINT("enter",
4378
4383
    length               [in]  length of name
4379
4384
    ref                  [in/out] if 'name' is resolved to a view field, ref is
4380
4385
                               set to point to the found view field
4381
 
    register_tree_change [in]  TRUE if ref is not stack variable and we
 
4386
    register_tree_change [in]  true if ref is not stack variable and we
4382
4387
                               need register changes in item tree
4383
4388
    actual_table         [out] the original table reference where the field
4384
4389
                               belongs - differs from 'table_list' only for
4398
4403
 
4399
4404
static Field *
4400
4405
find_field_in_natural_join(THD *thd, TABLE_LIST *table_ref, const char *name,
4401
 
                           uint length, Item **ref, bool register_tree_change,
 
4406
                           uint length __attribute__((__unused__)),
 
4407
                           Item **ref, bool register_tree_change,
4402
4408
                           TABLE_LIST **actual_table)
4403
4409
{
4404
4410
  List_iterator_fast<Natural_join_column>
4574
4580
    allow_rowid            [in]  do allow finding of "_rowid" field?
4575
4581
    cached_field_index_ptr [in]  cached position in field list (used to
4576
4582
                                 speedup lookup for fields in prepared tables)
4577
 
    register_tree_change   [in]  TRUE if ref is not stack variable and we
 
4583
    register_tree_change   [in]  true if ref is not stack variable and we
4578
4584
                                 need register changes in item tree
4579
4585
    actual_table           [out] the original table reference where the field
4580
4586
                                 belongs - differs from 'table_list' only for
4802
4808
                            except when non-unique fields were found
4803
4809
                          - REPORT_ALL_ERRORS
4804
4810
    check_privileges      need to check privileges
4805
 
    register_tree_change  TRUE if ref is not a stack variable and we
 
4811
    register_tree_change  true if ref is not a stack variable and we
4806
4812
                          to need register changes in item tree
4807
4813
 
4808
4814
  RETURN VALUES
4859
4865
      */
4860
4866
    if (table_ref->table)
4861
4867
      found= find_field_in_table(thd, table_ref->table, name, length,
4862
 
                                 TRUE, &(item->cached_field_index));
 
4868
                                 true, &(item->cached_field_index));
4863
4869
    else
4864
4870
      found= find_field_in_table_ref(thd, table_ref, name, length, item->name,
4865
4871
                                     NULL, NULL, ref, check_privileges,
4866
 
                                     TRUE, &(item->cached_field_index),
 
4872
                                     true, &(item->cached_field_index),
4867
4873
                                     register_tree_change,
4868
4874
                                     &actual_table);
4869
4875
    if (found)
5271
5277
    the list contains the same string.
5272
5278
 
5273
5279
  RETURN
5274
 
    TRUE  if find is in str_list
5275
 
    FALSE otherwise
 
5280
    true  if find is in str_list
 
5281
    false otherwise
5276
5282
*/
5277
5283
 
5278
5284
static bool
5286
5292
    if (find_length != curr_str->length())
5287
5293
      continue;
5288
5294
    if (!my_strcasecmp(system_charset_info, find, curr_str->ptr()))
5289
 
      return TRUE;
 
5295
      return true;
5290
5296
  }
5291
 
  return FALSE;
 
5297
  return false;
5292
5298
}
5293
5299
 
5294
5300
 
5307
5313
    is resolved only the supplied 'table_ref'.
5308
5314
 
5309
5315
  RETURN
5310
 
    FALSE  if all OK
5311
 
    TRUE   otherwise
 
5316
    false  if all OK
 
5317
    true   otherwise
5312
5318
*/
5313
5319
 
5314
5320
static bool
5316
5322
{
5317
5323
  Name_resolution_context *context;
5318
5324
  if (!(context= new (thd->mem_root) Name_resolution_context))
5319
 
    return TRUE;
 
5325
    return true;
5320
5326
  context->init();
5321
5327
  context->first_name_resolution_table=
5322
5328
    context->last_name_resolution_table= table_ref;
5323
5329
  item->context= context;
5324
 
  return FALSE;
 
5330
  return false;
5325
5331
}
5326
5332
 
5327
5333
 
5352
5358
    called for the previous level of NATURAL/USING joins.
5353
5359
 
5354
5360
  RETURN
5355
 
    TRUE   error when some common column is non-unique, or out of memory
5356
 
    FALSE  OK
 
5361
    true   error when some common column is non-unique, or out of memory
 
5362
    false  OK
5357
5363
*/
5358
5364
 
5359
5365
static bool
5362
5368
{
5363
5369
  Field_iterator_table_ref it_1, it_2;
5364
5370
  Natural_join_column *nj_col_1, *nj_col_2;
5365
 
  bool result= TRUE;
5366
 
  bool first_outer_loop= TRUE;
 
5371
  bool result= true;
 
5372
  bool first_outer_loop= true;
5367
5373
  /*
5368
5374
    Leaf table references to which new natural join columns are added
5369
5375
    if the leaves are != NULL.
5383
5389
 
5384
5390
  for (it_1.set(table_ref_1); !it_1.end_of_fields(); it_1.next())
5385
5391
  {
5386
 
    bool found= FALSE;
 
5392
    bool found= false;
5387
5393
    const char *field_name_1;
5388
5394
    /* true if field_name_1 is a member of using_fields */
5389
5395
    bool is_using_column_1;
5419
5425
      /*
5420
5426
        Compare the two columns and check for duplicate common fields.
5421
5427
        A common field is duplicate either if it was already found in
5422
 
        table_ref_2 (then found == TRUE), or if a field in table_ref_2
 
5428
        table_ref_2 (then found == true), or if a field in table_ref_2
5423
5429
        was already matched by some previous field in table_ref_1
5424
 
        (then cur_nj_col_2->is_common == TRUE).
 
5430
        (then cur_nj_col_2->is_common == true).
5425
5431
        Note that it is too early to check the columns outside of the
5426
5432
        USING list for ambiguity because they are not actually "referenced"
5427
5433
        here. These columns must be checked only on unqualified reference 
5437
5443
          goto err;
5438
5444
        }
5439
5445
        nj_col_2= cur_nj_col_2;
5440
 
        found= TRUE;
 
5446
        found= true;
5441
5447
      }
5442
5448
    }
5443
5449
    if (first_outer_loop && leaf_2)
5446
5452
        Make sure that the next inner loop "knows" that all columns
5447
5453
        are materialized already.
5448
5454
      */
5449
 
      leaf_2->is_join_columns_complete= TRUE;
5450
 
      first_outer_loop= FALSE;
 
5455
      leaf_2->is_join_columns_complete= true;
 
5456
      first_outer_loop= false;
5451
5457
    }
5452
5458
    if (!found)
5453
5459
      continue;                                 // No matching field
5511
5517
                   table_ref_1 : table_ref_2),
5512
5518
                  eq_cond);
5513
5519
 
5514
 
      nj_col_1->is_common= nj_col_2->is_common= TRUE;
 
5520
      nj_col_1->is_common= nj_col_2->is_common= true;
5515
5521
      DBUG_PRINT ("info", ("%s.%s and %s.%s are common", 
5516
5522
                           nj_col_1->table_name() ? 
5517
5523
                             nj_col_1->table_name() : "", 
5542
5548
    }
5543
5549
  }
5544
5550
  if (leaf_1)
5545
 
    leaf_1->is_join_columns_complete= TRUE;
 
5551
    leaf_1->is_join_columns_complete= true;
5546
5552
 
5547
5553
  /*
5548
5554
    Everything is OK.
5551
5557
    we check for this error in store_natural_using_join_columns() when
5552
5558
    (found_using_fields < length(join_using_fields)).
5553
5559
  */
5554
 
  result= FALSE;
 
5560
  result= false;
5555
5561
 
5556
5562
err:
5557
5563
  DBUG_RETURN(result);
5590
5596
    for the join that is being processed.
5591
5597
 
5592
5598
  RETURN
5593
 
    TRUE    error: Some common column is ambiguous
5594
 
    FALSE   OK
 
5599
    true    error: Some common column is ambiguous
 
5600
    false   OK
5595
5601
*/
5596
5602
 
5597
5603
static bool
5598
 
store_natural_using_join_columns(THD *thd, TABLE_LIST *natural_using_join,
 
5604
store_natural_using_join_columns(THD *thd __attribute__((__unused__)),
 
5605
                                 TABLE_LIST *natural_using_join,
5599
5606
                                 TABLE_LIST *table_ref_1,
5600
5607
                                 TABLE_LIST *table_ref_2,
5601
5608
                                 List<String> *using_fields,
5603
5610
{
5604
5611
  Field_iterator_table_ref it_1, it_2;
5605
5612
  Natural_join_column *nj_col_1, *nj_col_2;
5606
 
  bool result= TRUE;
 
5613
  bool result= true;
5607
5614
  List<Natural_join_column> *non_join_columns;
5608
5615
  DBUG_ENTER("store_natural_using_join_columns");
5609
5616
 
5621
5628
    {
5622
5629
      natural_using_join->join_columns->push_back(nj_col_1);
5623
5630
      /* Reset the common columns for the next call to mark_common_columns. */
5624
 
      nj_col_1->is_common= FALSE;
 
5631
      nj_col_1->is_common= false;
5625
5632
    }
5626
5633
    else
5627
5634
      non_join_columns->push_back(nj_col_1);
5668
5675
    else
5669
5676
    {
5670
5677
      /* Reset the common columns for the next call to mark_common_columns. */
5671
 
      nj_col_2->is_common= FALSE;
 
5678
      nj_col_2->is_common= false;
5672
5679
    }
5673
5680
  }
5674
5681
 
5675
5682
  if (non_join_columns->elements > 0)
5676
5683
    natural_using_join->join_columns->concat(non_join_columns);
5677
 
  natural_using_join->is_join_columns_complete= TRUE;
 
5684
  natural_using_join->is_join_columns_complete= true;
5678
5685
 
5679
 
  result= FALSE;
 
5686
  result= false;
5680
5687
 
5681
5688
err:
5682
5689
  DBUG_RETURN(result);
5709
5716
    from the right to the left in the FROM clause.
5710
5717
 
5711
5718
  RETURN
5712
 
    TRUE   Error
5713
 
    FALSE  OK
 
5719
    true   Error
 
5720
    false  OK
5714
5721
*/
5715
5722
 
5716
5723
static bool
5718
5725
                             TABLE_LIST *left_neighbor,
5719
5726
                             TABLE_LIST *right_neighbor)
5720
5727
{
5721
 
  bool result= TRUE;
 
5728
  bool result= true;
5722
5729
 
5723
5730
  DBUG_ENTER("store_top_level_join_columns");
5724
5731
 
5820
5827
    */
5821
5828
    table_ref_1->natural_join= table_ref_2->natural_join= NULL;
5822
5829
 
5823
 
    /* Add a TRUE condition to outer joins that have no common columns. */
 
5830
    /* Add a true condition to outer joins that have no common columns. */
5824
5831
    if (table_ref_2->outer_join &&
5825
5832
        !table_ref_1->on_expr && !table_ref_2->on_expr)
5826
5833
      table_ref_2->on_expr= new Item_int((longlong) 1,1);   /* Always true. */
5841
5848
    else
5842
5849
      table_ref->next_name_resolution_table= NULL;
5843
5850
  }
5844
 
  result= FALSE; /* All is OK. */
 
5851
  result= false; /* All is OK. */
5845
5852
 
5846
5853
err:
5847
5854
  DBUG_RETURN(result);
5869
5876
    to the left in the FROM clause.
5870
5877
 
5871
5878
  RETURN
5872
 
    TRUE   Error
5873
 
    FALSE  OK
 
5879
    true   Error
 
5880
    false  OK
5874
5881
*/
5875
5882
static bool setup_natural_join_row_types(THD *thd,
5876
5883
                                         List<TABLE_LIST> *from_clause,
5878
5885
{
5879
5886
  thd->where= "from clause";
5880
5887
  if (from_clause->elements == 0)
5881
 
    return FALSE; /* We come here in the case of UNIONs. */
 
5888
    return false; /* We come here in the case of UNIONs. */
5882
5889
 
5883
5890
  List_iterator_fast<TABLE_LIST> table_ref_it(*from_clause);
5884
5891
  TABLE_LIST *table_ref; /* Current table reference. */
5897
5904
    {
5898
5905
      if (store_top_level_join_columns(thd, table_ref,
5899
5906
                                       left_neighbor, right_neighbor))
5900
 
        return TRUE;
 
5907
        return true;
5901
5908
      if (left_neighbor)
5902
5909
      {
5903
5910
        TABLE_LIST *first_leaf_on_the_right;
5918
5925
  context->first_name_resolution_table=
5919
5926
    right_neighbor->first_leaf_for_name_resolution();
5920
5927
 
5921
 
  return FALSE;
 
5928
  return false;
5922
5929
}
5923
5930
 
5924
5931
 
5926
5933
** Expand all '*' in given fields
5927
5934
****************************************************************************/
5928
5935
 
5929
 
int setup_wild(THD *thd, TABLE_LIST *tables, List<Item> &fields,
5930
 
               List<Item> *sum_func_list,
5931
 
               uint wild_num)
 
5936
int setup_wild(THD *thd,
 
5937
               TABLE_LIST *tables __attribute__((__unused__)),
 
5938
               List<Item> &fields,
 
5939
               List<Item> *sum_func_list,
 
5940
               uint wild_num)
5932
5941
{
5933
5942
  if (!wild_num)
5934
5943
    return(0);
6031
6040
      thd->lex->allow_sum_func= save_allow_sum_func;
6032
6041
      thd->mark_used_columns= save_mark_used_columns;
6033
6042
      DBUG_PRINT("info", ("thd->mark_used_columns: %d", thd->mark_used_columns));
6034
 
      DBUG_RETURN(TRUE); /* purecov: inspected */
 
6043
      DBUG_RETURN(true); /* purecov: inspected */
6035
6044
    }
6036
6045
    if (ref)
6037
6046
      *(ref++)= item;
6098
6107
    table->map is not set and all Item_field will be regarded as const items.
6099
6108
 
6100
6109
  RETURN
6101
 
    FALSE ok;  In this case *map will includes the chosen index
6102
 
    TRUE  error
 
6110
    false ok;  In this case *map will includes the chosen index
 
6111
    true  error
6103
6112
*/
6104
6113
 
6105
6114
bool setup_tables(THD *thd, Name_resolution_context *context,
6173
6182
    table leaves list for access to all the tables that belong to a view
6174
6183
 
6175
6184
  RETURN
6176
 
    FALSE ok;  In this case *map will include the chosen index
6177
 
    TRUE  error
 
6185
    false ok;  In this case *map will include the chosen index
 
6186
    true  error
6178
6187
*/
6179
6188
bool setup_tables_and_check_access(THD *thd, 
6180
6189
                                   Name_resolution_context *context,
6188
6197
 
6189
6198
  if (setup_tables(thd, context, from_clause, tables,
6190
6199
                   &leaves_tmp, select_insert))
6191
 
    return TRUE;
 
6200
    return true;
6192
6201
 
6193
6202
  if (leaves)
6194
6203
    *leaves= leaves_tmp;
6197
6206
  {
6198
6207
    if (leaves_tmp->belong_to_view)
6199
6208
    {
6200
 
      return TRUE;
 
6209
      return true;
6201
6210
    }
6202
6211
    first_table= 0;
6203
6212
  }
6204
 
  return FALSE;
 
6213
  return false;
6205
6214
}
6206
6215
 
6207
6216
 
6265
6274
 
6266
6275
bool
6267
6276
insert_fields(THD *thd, Name_resolution_context *context, const char *db_name,
6268
 
              const char *table_name, List_iterator<Item> *it,
6269
 
              bool any_privileges)
 
6277
              const char *table_name, List_iterator<Item> *it,
 
6278
              bool any_privileges __attribute__((__unused__)))
6270
6279
{
6271
6280
  Field_iterator_table_ref field_iterator;
6272
6281
  bool found;
6285
6294
    db_name= name_buff;
6286
6295
  }
6287
6296
 
6288
 
  found= FALSE;
 
6297
  found= false;
6289
6298
 
6290
6299
  /*
6291
6300
    If table names are qualified, then loop over all tables used in the query,
6328
6337
      Item *item;
6329
6338
 
6330
6339
      if (!(item= field_iterator.create_item(thd)))
6331
 
        DBUG_RETURN(TRUE);
 
6340
        DBUG_RETURN(true);
6332
6341
 
6333
6342
      if (!found)
6334
6343
      {
6335
 
        found= TRUE;
 
6344
        found= true;
6336
6345
        it->replace(item); /* Replace '*' with the first found item. */
6337
6346
      }
6338
6347
      else
6356
6365
          */
6357
6366
          Natural_join_column *nj_col;
6358
6367
          if (!(nj_col= field_iterator.get_natural_column_ref()))
6359
 
            DBUG_RETURN(TRUE);
 
6368
            DBUG_RETURN(true);
6360
6369
          DBUG_ASSERT(nj_col->table_field);
6361
6370
          field_table= nj_col->table_ref->table;
6362
6371
          if (field_table)
6382
6391
      table->used_fields= table->s->fields;
6383
6392
  }
6384
6393
  if (found)
6385
 
    DBUG_RETURN(FALSE);
 
6394
    DBUG_RETURN(false);
6386
6395
 
6387
6396
  /*
6388
6397
    TODO: in the case when we skipped all columns because there was a
6394
6403
  else
6395
6404
    my_error(ER_BAD_TABLE_ERROR, MYF(0), table_name);
6396
6405
 
6397
 
  DBUG_RETURN(TRUE);
 
6406
  DBUG_RETURN(true);
6398
6407
}
6399
6408
 
6400
6409
 
6412
6421
    TODO
6413
6422
 
6414
6423
  RETURN
6415
 
    TRUE  if some error occured (e.g. out of memory)
6416
 
    FALSE if all is OK
 
6424
    true  if some error occured (e.g. out of memory)
 
6425
    false if all is OK
6417
6426
*/
6418
6427
 
6419
 
int setup_conds(THD *thd, TABLE_LIST *tables, TABLE_LIST *leaves,
 
6428
int setup_conds(THD *thd, TABLE_LIST *tables __attribute__((__unused__)),
 
6429
                TABLE_LIST *leaves,
6420
6430
                COND **conds)
6421
6431
{
6422
6432
  SELECT_LEX *select_lex= thd->lex->current_select;
6423
6433
  TABLE_LIST *table= NULL;      // For HP compilers
6424
6434
  void *save_thd_marker= thd->thd_marker;
6425
6435
  /*
6426
 
    it_is_update set to TRUE when tables of primary SELECT_LEX (SELECT_LEX
 
6436
    it_is_update set to true when tables of primary SELECT_LEX (SELECT_LEX
6427
6437
    which belong to LEX, i.e. most up SELECT) will be updated by
6428
6438
    INSERT/UPDATE/LOAD
6429
6439
    NOTE: using this condition helps to prevent call of prepare_check_option()
6502
6512
    thd           thread handler
6503
6513
    fields        Item_fields list to be filled
6504
6514
    values        values to fill with
6505
 
    ignore_errors TRUE if we should ignore errors
 
6515
    ignore_errors true if we should ignore errors
6506
6516
 
6507
6517
  NOTE
6508
6518
    fill_record() may set table->auto_increment_field_not_null and a
6510
6520
    function.
6511
6521
 
6512
6522
  RETURN
6513
 
    FALSE   OK
6514
 
    TRUE    error occured
 
6523
    false   OK
 
6524
    true    error occured
6515
6525
*/
6516
6526
 
6517
6527
bool
6540
6550
      goto err;
6541
6551
    }
6542
6552
    table= field->field->table;
6543
 
    table->auto_increment_field_not_null= FALSE;
 
6553
    table->auto_increment_field_not_null= false;
6544
6554
    f.rewind();
6545
6555
  }
6546
6556
  while ((fld= f++))
6554
6564
    Field *rfield= field->field;
6555
6565
    table= rfield->table;
6556
6566
    if (rfield == table->next_number_field)
6557
 
      table->auto_increment_field_not_null= TRUE;
 
6567
      table->auto_increment_field_not_null= true;
6558
6568
    if ((value->save_in_field(rfield, 0) < 0) && !ignore_errors)
6559
6569
    {
6560
6570
      my_message(ER_UNKNOWN_ERROR, ER(ER_UNKNOWN_ERROR), MYF(0));
6564
6574
  DBUG_RETURN(thd->is_error());
6565
6575
err:
6566
6576
  if (table)
6567
 
    table->auto_increment_field_not_null= FALSE;
6568
 
  DBUG_RETURN(TRUE);
 
6577
    table->auto_increment_field_not_null= false;
 
6578
  DBUG_RETURN(true);
6569
6579
}
6570
6580
 
6571
6581
 
6577
6587
    thd           thread handler
6578
6588
    ptr           pointer on pointer to record
6579
6589
    values        list of fields
6580
 
    ignore_errors TRUE if we should ignore errors
 
6590
    ignore_errors true if we should ignore errors
6581
6591
 
6582
6592
  NOTE
6583
6593
    fill_record() may set table->auto_increment_field_not_null and a
6585
6595
    function.
6586
6596
 
6587
6597
  RETURN
6588
 
    FALSE   OK
6589
 
    TRUE    error occured
 
6598
    false   OK
 
6599
    true    error occured
6590
6600
*/
6591
6601
 
6592
6602
bool
6593
 
fill_record(THD *thd, Field **ptr, List<Item> &values, bool ignore_errors)
 
6603
fill_record(THD *thd, Field **ptr, List<Item> &values,
 
6604
            bool ignore_errors __attribute__((__unused__)))
6594
6605
{
6595
6606
  List_iterator_fast<Item> v(values);
6596
6607
  Item *value;
6609
6620
      thus we safely can take table from the first field.
6610
6621
    */
6611
6622
    table= (*ptr)->table;
6612
 
    table->auto_increment_field_not_null= FALSE;
 
6623
    table->auto_increment_field_not_null= false;
6613
6624
  }
6614
6625
  while ((field = *ptr++) && ! thd->is_error())
6615
6626
  {
6616
6627
    value=v++;
6617
6628
    table= field->table;
6618
6629
    if (field == table->next_number_field)
6619
 
      table->auto_increment_field_not_null= TRUE;
 
6630
      table->auto_increment_field_not_null= true;
6620
6631
    if (value->save_in_field(field, 0) < 0)
6621
6632
      goto err;
6622
6633
  }
6624
6635
 
6625
6636
err:
6626
6637
  if (table)
6627
 
    table->auto_increment_field_not_null= FALSE;
6628
 
  DBUG_RETURN(TRUE);
 
6638
    table->auto_increment_field_not_null= false;
 
6639
  DBUG_RETURN(true);
6629
6640
}
6630
6641
 
6631
6642
 
6667
6678
      {
6668
6679
        char *ext= fn_ext(file->name);
6669
6680
        uint ext_len= strlen(ext);
6670
 
        uint filePath_len= my_snprintf(filePath, sizeof(filePath),
6671
 
                                       "%s%c%s", tmpdir, FN_LIBCHAR,
6672
 
                                       file->name);
 
6681
        uint filePath_len= snprintf(filePath, sizeof(filePath),
 
6682
                                    "%s%c%s", tmpdir, FN_LIBCHAR,
 
6683
                                    file->name);
6673
6684
        if (!bcmp((uchar*) reg_ext, (uchar*) ext, ext_len))
6674
6685
        {
6675
6686
          handler *handler_file= 0;
6939
6950
    with this call.
6940
6951
 
6941
6952
  RETURN
6942
 
    FALSE   Success
6943
 
    TRUE    Error
 
6953
    false   Success
 
6954
    true    Error
6944
6955
*/
6945
6956
 
6946
6957
bool
6978
6989
                                 MYSQL_LOCK_IGNORE_FLUSH, &not_used);
6979
6990
  }
6980
6991
  if (thd->lock)
6981
 
    DBUG_RETURN(FALSE);
 
6992
    DBUG_RETURN(false);
6982
6993
 
6983
6994
error:
6984
6995
  close_system_tables(thd, backup);
6985
6996
 
6986
 
  DBUG_RETURN(TRUE);
 
6997
  DBUG_RETURN(true);
6987
6998
}
6988
6999
 
6989
7000