~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to sql/sql_base.cc

  • Committer: Brian Aker
  • Date: 2008-07-05 17:02:05 UTC
  • Revision ID: brian@tangent.org-20080705170205-ezff9is4e7hpa3x2
Conversion of handler type.

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
  }
747
747
         won't proceed while write-locked tables are being reopened by other
748
748
         threads.
749
749
 
750
 
  @remark THD can be NULL, but then wait_for_refresh must be FALSE
 
750
  @remark THD can be NULL, but then wait_for_refresh must be false
751
751
          and tables must be NULL.
752
752
*/
753
753
 
933
933
{
934
934
  uint idx;
935
935
  TABLE_LIST tmp, *tables= NULL;
936
 
  bool result= FALSE;
 
936
  bool result= false;
937
937
  DBUG_ENTER("close_cached_connections");
938
938
  DBUG_ASSERT(thd);
939
939
 
970
970
  }
971
971
 
972
972
  if (tables)
973
 
    result= close_cached_tables(thd, tables, TRUE, FALSE, FALSE);
 
973
    result= close_cached_tables(thd, tables, true, false, false);
974
974
 
975
975
  if (!have_lock)
976
976
    VOID(pthread_mutex_unlock(&LOCK_open));
1146
1146
   */
1147
1147
  if (!(thd->state_flags & Open_tables_state::BACKUPS_AVAIL))
1148
1148
  {
1149
 
    thd->main_da.can_overwrite_status= TRUE;
 
1149
    thd->main_da.can_overwrite_status= true;
1150
1150
    ha_autocommit_or_rollback(thd, thd->is_error());
1151
 
    thd->main_da.can_overwrite_status= FALSE;
 
1151
    thd->main_da.can_overwrite_status= false;
1152
1152
    thd->transaction.stmt.reset();
1153
1153
  }
1154
1154
 
1175
1175
      handled either before writing a query log event (inside
1176
1176
      binlog_query()) or when preparing a pending event.
1177
1177
     */
1178
 
    thd->binlog_flush_pending_rows_event(TRUE);
 
1178
    thd->binlog_flush_pending_rows_event(true);
1179
1179
    mysql_unlock_tables(thd, thd->lock);
1180
1180
    thd->lock=0;
1181
1181
  }
1256
1256
  TABLE *next= NULL;
1257
1257
  TABLE *prev_table;
1258
1258
  /* Assume thd->options has OPTION_QUOTE_SHOW_CREATE */
1259
 
  bool was_quote_show= TRUE;
 
1259
  bool was_quote_show= true;
1260
1260
 
1261
1261
  if (!thd->temporary_tables)
1262
1262
    return;
1278
1278
  uint stub_len= sizeof(stub) - 1;
1279
1279
  char buf[256];
1280
1280
  String s_query= String(buf, sizeof(buf), system_charset_info);
1281
 
  bool found_user_tables= FALSE;
 
1281
  bool found_user_tables= false;
1282
1282
 
1283
1283
  memcpy(buf, stub, stub_len);
1284
1284
 
1361
1361
      thd->variables.character_set_client= system_charset_info;
1362
1362
      Query_log_event qinfo(thd, s_query.ptr(),
1363
1363
                            s_query.length() - 1 /* to remove trailing ',' */,
1364
 
                            0, FALSE);
 
1364
                            0, false);
1365
1365
      thd->variables.character_set_client= cs_save;
1366
1366
      /*
1367
1367
        Imagine the thread had created a temp table, then was doing a
1622
1622
    If LOCK TABLES list is not empty and contains this table,
1623
1623
    unlock the table and remove the table from this list.
1624
1624
  */
1625
 
  mysql_lock_remove(thd, thd->locked_tables, table, FALSE);
 
1625
  mysql_lock_remove(thd, thd->locked_tables, table, false);
1626
1626
  close_temporary_table(thd, table, 1, 1);
1627
1627
  DBUG_RETURN(0);
1628
1628
}
1754
1754
 
1755
1755
    @param  thd     Thread context
1756
1756
    @param  find    Table to remove
1757
 
    @param  unlock  TRUE  - free all locks on tables removed that are
 
1757
    @param  unlock  true  - free all locks on tables removed that are
1758
1758
                            done with LOCK TABLES
1759
 
                    FALSE - otherwise
 
1759
                    false - otherwise
1760
1760
 
1761
 
    @note When unlock parameter is FALSE or current thread doesn't have
 
1761
    @note When unlock parameter is false or current thread doesn't have
1762
1762
          any tables locked with LOCK TABLES, tables are assumed to be
1763
1763
          not locked (for example already unlocked).
1764
1764
*/
1788
1788
        !memcmp(list->s->table_cache_key.str, key, key_length))
1789
1789
    {
1790
1790
      if (unlock && thd->locked_tables)
1791
 
        mysql_lock_remove(thd, thd->locked_tables, list, TRUE);
 
1791
        mysql_lock_remove(thd, thd->locked_tables, list, true);
1792
1792
 
1793
1793
      /* Remove table from open_tables list. */
1794
1794
      *prev= list->next;
1840
1840
      unlink_open_table() also tells threads waiting for refresh or close
1841
1841
      that something has happened.
1842
1842
    */
1843
 
    unlink_open_table(thd, table, FALSE);
 
1843
    unlink_open_table(thd, table, false);
1844
1844
    quick_rm_table(table_type, db_name, table_name, 0);
1845
1845
    VOID(pthread_mutex_unlock(&LOCK_open));
1846
1846
  }
1898
1898
  @param thd current thread context
1899
1899
  @param tables table list containing one table to open.
1900
1900
 
1901
 
  @return FALSE on success, TRUE otherwise.
 
1901
  @return false on success, true otherwise.
1902
1902
*/
1903
1903
 
1904
1904
bool name_lock_locked_table(THD *thd, TABLE_LIST *tables)
1919
1919
      other statement will open this table.
1920
1920
    */
1921
1921
    wait_while_table_is_used(thd, tables->table, HA_EXTRA_FORCE_REOPEN);
1922
 
    DBUG_RETURN(FALSE);
 
1922
    DBUG_RETURN(false);
1923
1923
  }
1924
1924
 
1925
 
  DBUG_RETURN(TRUE);
 
1925
  DBUG_RETURN(true);
1926
1926
}
1927
1927
 
1928
1928
 
1935
1935
      table_list  TABLE_LIST object for table to be open, TABLE_LIST::table
1936
1936
                  member should point to TABLE object which was used for
1937
1937
                  name-locking.
1938
 
      link_in     TRUE  - if TABLE object for table to be opened should be
 
1938
      link_in     true  - if TABLE object for table to be opened should be
1939
1939
                          linked into THD::open_tables list.
1940
 
                  FALSE - placeholder used for name-locking is already in
 
1940
                  false - placeholder used for name-locking is already in
1941
1941
                          this list so we only need to preserve TABLE::next
1942
1942
                          pointer.
1943
1943
 
1945
1945
    This function assumes that its caller already acquired LOCK_open mutex.
1946
1946
 
1947
1947
  RETURN VALUE
1948
 
    FALSE - Success
1949
 
    TRUE  - Error
 
1948
    false - Success
 
1949
    true  - Error
1950
1950
*/
1951
1951
 
1952
1952
bool reopen_name_locked_table(THD* thd, TABLE_LIST* table_list, bool link_in)
1960
1960
  safe_mutex_assert_owner(&LOCK_open);
1961
1961
 
1962
1962
  if (thd->killed || !table)
1963
 
    DBUG_RETURN(TRUE);
 
1963
    DBUG_RETURN(true);
1964
1964
 
1965
1965
  orig_table= *table;
1966
1966
 
1976
1976
      object to its original state.
1977
1977
    */
1978
1978
    *table= orig_table;
1979
 
    DBUG_RETURN(TRUE);
 
1979
    DBUG_RETURN(true);
1980
1980
  }
1981
1981
 
1982
1982
  share= table->s;
2011
2011
  table->const_table=0;
2012
2012
  table->null_row= table->maybe_null= table->force_index= 0;
2013
2013
  table->status=STATUS_NO_RECORD;
2014
 
  DBUG_RETURN(FALSE);
 
2014
  DBUG_RETURN(false);
2015
2015
}
2016
2016
 
2017
2017
 
2084
2084
          'table' parameter can be set to NULL for some situations when
2085
2085
          table does not really exist.
2086
2086
 
2087
 
    @retval  TRUE   Error occured (OOM)
2088
 
    @retval  FALSE  Success. 'table' parameter set according to above rules.
 
2087
    @retval  true   Error occured (OOM)
 
2088
    @retval  false  Success. 'table' parameter set according to above rules.
2089
2089
*/
2090
2090
 
2091
2091
bool lock_table_name_if_not_cached(THD *thd, const char *db,
2103
2103
    VOID(pthread_mutex_unlock(&LOCK_open));
2104
2104
    DBUG_PRINT("info", ("Table is cached, name-lock is not obtained"));
2105
2105
    *table= 0;
2106
 
    DBUG_RETURN(FALSE);
 
2106
    DBUG_RETURN(false);
2107
2107
  }
2108
2108
  if (!(*table= table_cache_insert_placeholder(thd, key, key_length)))
2109
2109
  {
2110
2110
    VOID(pthread_mutex_unlock(&LOCK_open));
2111
 
    DBUG_RETURN(TRUE);
 
2111
    DBUG_RETURN(true);
2112
2112
  }
2113
2113
  (*table)->open_placeholder= 1;
2114
2114
  (*table)->next= thd->open_tables;
2115
2115
  thd->open_tables= *table;
2116
2116
  VOID(pthread_mutex_unlock(&LOCK_open));
2117
 
  DBUG_RETURN(FALSE);
 
2117
  DBUG_RETURN(false);
2118
2118
}
2119
2119
 
2120
2120
 
2124
2124
 
2125
2125
    @param       thd     Thread context
2126
2126
    @param       table   Table list element
2127
 
    @param[out]  exists  Out parameter which is set to TRUE if table
2128
 
                         exists and to FALSE otherwise.
 
2127
    @param[out]  exists  Out parameter which is set to true if table
 
2128
                         exists and to false otherwise.
2129
2129
 
2130
2130
    @note This function assumes that caller owns LOCK_open mutex.
2131
2131
          It also assumes that the fact that there are no name-locks
2135
2135
          of engines (e.g. it was created on another node of NDB cluster)
2136
2136
          this function will fetch and create proper .FRM file for it.
2137
2137
 
2138
 
    @retval  TRUE   Some error occured
2139
 
    @retval  FALSE  No error. 'exists' out parameter set accordingly.
 
2138
    @retval  true   Some error occured
 
2139
    @retval  false  No error. 'exists' out parameter set accordingly.
2140
2140
*/
2141
2141
 
2142
2142
bool check_if_table_exists(THD *thd, TABLE_LIST *table, bool *exists)
2147
2147
 
2148
2148
  safe_mutex_assert_owner(&LOCK_open);
2149
2149
 
2150
 
  *exists= TRUE;
 
2150
  *exists= true;
2151
2151
 
2152
2152
  if (get_cached_table_share(table->db, table->table_name))
2153
 
    DBUG_RETURN(FALSE);
 
2153
    DBUG_RETURN(false);
2154
2154
 
2155
2155
  build_table_filename(path, sizeof(path) - 1, table->db, table->table_name,
2156
2156
                       reg_ext, 0);
2157
2157
 
2158
2158
  if (!access(path, F_OK))
2159
 
    DBUG_RETURN(FALSE);
 
2159
    DBUG_RETURN(false);
2160
2160
 
2161
2161
  /* .FRM file doesn't exist. Check if some engine can provide it. */
2162
2162
 
2165
2165
  if (rc < 0)
2166
2166
  {
2167
2167
    /* Table does not exists in engines as well. */
2168
 
    *exists= FALSE;
2169
 
    DBUG_RETURN(FALSE);
 
2168
    *exists= false;
 
2169
    DBUG_RETURN(false);
2170
2170
  }
2171
2171
  else if (!rc)
2172
2172
  {
2173
2173
    /* Table exists in some engine and .FRM for it was created. */
2174
 
    DBUG_RETURN(FALSE);
 
2174
    DBUG_RETURN(false);
2175
2175
  }
2176
2176
  else /* (rc > 0) */
2177
2177
  {
2178
2178
    my_printf_error(ER_UNKNOWN_ERROR, "Failed to open '%-.64s', error while "
2179
2179
                    "unpacking from engine", MYF(0), table->table_name);
2180
 
    DBUG_RETURN(TRUE);
 
2180
    DBUG_RETURN(true);
2181
2181
  }
2182
2182
}
2183
2183
 
2273
2273
          DBUG_RETURN(0);
2274
2274
        }
2275
2275
        table->query_id= thd->query_id;
2276
 
        thd->thread_specific_used= TRUE;
 
2276
        thd->thread_specific_used= true;
2277
2277
        DBUG_PRINT("info",("Using temporary table"));
2278
2278
        goto reset;
2279
2279
      }
2646
2646
  table->file->ft_handler= 0;
2647
2647
  /* Catch wrong handling of the auto_increment_field_not_null. */
2648
2648
  DBUG_ASSERT(!table->auto_increment_field_not_null);
2649
 
  table->auto_increment_field_not_null= FALSE;
 
2649
  table->auto_increment_field_not_null= false;
2650
2650
  if (table->timestamp_field)
2651
2651
    table->timestamp_field_type= table->timestamp_field->get_auto_set_type();
2652
2652
  table->pos_in_table_list= table_list;
2819
2819
    {
2820
2820
      if (thd->locked_tables)
2821
2821
      {
2822
 
        mysql_lock_remove(thd, thd->locked_tables, table, TRUE);
 
2822
        mysql_lock_remove(thd, thd->locked_tables, table, true);
2823
2823
      }
2824
2824
      table->open_placeholder= 1;
2825
2825
      close_handle_and_leave_table_as_lock(table);
2846
2846
 
2847
2847
    @note One should have lock on LOCK_open when calling this.
2848
2848
 
2849
 
    @return FALSE in case of success, TRUE - otherwise.
 
2849
    @return false in case of success, true - otherwise.
2850
2850
*/
2851
2851
 
2852
2852
bool reopen_tables(THD *thd, bool get_locks, bool mark_share_as_old)
2948
2948
 
2949
2949
    @param thd           Thread context
2950
2950
    @param table         Head of the list of TABLE objects
2951
 
    @param morph_locks   TRUE  - remove locks which we have on tables being closed
 
2951
    @param morph_locks   true  - remove locks which we have on tables being closed
2952
2952
                                 but ensure that no DML or DDL will sneak in before
2953
2953
                                 we will re-open the table (i.e. temporarily morph
2954
2954
                                 our table-level locks into name-locks).
2955
 
                         FALSE - otherwise
 
2955
                         false - otherwise
2956
2956
    @param send_refresh  Should we awake waiters even if we didn't close any tables?
2957
2957
*/
2958
2958
 
2988
2988
              lock on it. This will also give them a chance to close their
2989
2989
              instances of this table.
2990
2990
            */
2991
 
            mysql_lock_abort(thd, ulcktbl, TRUE);
2992
 
            mysql_lock_remove(thd, thd->locked_tables, ulcktbl, TRUE);
 
2991
            mysql_lock_abort(thd, ulcktbl, true);
 
2992
            mysql_lock_remove(thd, thd->locked_tables, ulcktbl, true);
2993
2993
            ulcktbl->lock_count= 0;
2994
2994
          }
2995
2995
          if ((ulcktbl != table) && ulcktbl->db_stat)
3157
3157
    if (!strcmp(table->s->table_name.str, table_name) &&
3158
3158
        !strcmp(table->s->db.str, db))
3159
3159
    {
3160
 
      mysql_lock_remove(thd, thd->locked_tables, table, TRUE);
 
3160
      mysql_lock_remove(thd, thd->locked_tables, table, true);
3161
3161
 
3162
3162
      if (!found)
3163
3163
      {
3208
3208
        !strcmp(table->s->db.str, db))
3209
3209
    {
3210
3210
      /* If MERGE child, forward lock handling to parent. */
3211
 
      mysql_lock_abort(thd, table, TRUE);
 
3211
      mysql_lock_abort(thd, table, true);
3212
3212
      break;
3213
3213
    }
3214
3214
  }
3364
3364
    if (!entry->s || !entry->s->crashed)
3365
3365
      goto err;
3366
3366
     // Code below is for repairing a crashed file
3367
 
     if ((error= lock_table_name(thd, table_list, TRUE)))
 
3367
     if ((error= lock_table_name(thd, table_list, true)))
3368
3368
     {
3369
3369
       if (error < 0)
3370
3370
        goto err;
3422
3422
        end = strxmov(strmov(query, "DELETE FROM `"),
3423
3423
                      share->db.str,"`.`",share->table_name.str,"`", NullS);
3424
3424
        thd->binlog_query(THD::STMT_QUERY_TYPE,
3425
 
                          query, (ulong)(end-query), FALSE, FALSE);
 
3425
                          query, (ulong)(end-query), false, false);
3426
3426
        my_free(query, MYF(0));
3427
3427
      }
3428
3428
      else
3506
3506
    DBUG_PRINT("tcache", ("opening table: '%s'.'%s'  item: 0x%lx",
3507
3507
                          tables->db, tables->table_name, (long) tables));
3508
3508
 
3509
 
    safe_to_ignore_table= FALSE;
 
3509
    safe_to_ignore_table= false;
3510
3510
 
3511
3511
    /*
3512
3512
      Ignore placeholders for derived tables. After derived tables
3772
3772
    derived     - if to handle derived tables
3773
3773
 
3774
3774
  RETURN
3775
 
    FALSE - ok
3776
 
    TRUE  - error
 
3775
    false - ok
 
3776
    true  - error
3777
3777
 
3778
3778
  NOTE
3779
3779
    The lock will automaticaly be freed by close_thread_tables()
3814
3814
      (mysql_handle_derived(thd->lex, &mysql_derived_prepare) ||
3815
3815
       (thd->fill_derived_tables() &&
3816
3816
        mysql_handle_derived(thd->lex, &mysql_derived_filling))))
3817
 
    DBUG_RETURN(TRUE); /* purecov: inspected */
 
3817
    DBUG_RETURN(true); /* purecov: inspected */
3818
3818
  DBUG_RETURN(0);
3819
3819
}
3820
3820
 
3831
3831
                  done a flush or namelock on it.
3832
3832
 
3833
3833
  RETURN
3834
 
    FALSE - ok
3835
 
    TRUE  - error
 
3834
    false - ok
 
3835
    true  - error
3836
3836
 
3837
3837
  NOTE 
3838
3838
    This is to be used on prepare stage when you don't read any
3846
3846
  DBUG_ASSERT(!thd->fill_derived_tables());
3847
3847
  if (open_tables(thd, &tables, &counter, flags) ||
3848
3848
      mysql_handle_derived(thd->lex, &mysql_derived_prepare))
3849
 
    DBUG_RETURN(TRUE); /* purecov: inspected */
 
3849
    DBUG_RETURN(true); /* purecov: inspected */
3850
3850
  DBUG_RETURN(0);
3851
3851
}
3852
3852
 
3894
3894
  {
3895
3895
    handler::Table_flags flags_some_set= handler::Table_flags();
3896
3896
    handler::Table_flags flags_all_set= ~handler::Table_flags();
3897
 
    my_bool multi_engine= FALSE;
 
3897
    my_bool multi_engine= false;
3898
3898
    void* prev_ht= NULL;
3899
3899
    for (TABLE_LIST *table= tables; table; table= table->next_global)
3900
3900
    {
3906
3906
                            FLAGSTR(flags, HA_BINLOG_STMT_CAPABLE),
3907
3907
                            FLAGSTR(flags, HA_BINLOG_ROW_CAPABLE)));
3908
3908
        if (prev_ht && prev_ht != table->table->file->ht)
3909
 
          multi_engine= TRUE;
 
3909
          multi_engine= true;
3910
3910
        prev_ht= table->table->file->ht;
3911
3911
        flags_all_set &= flags;
3912
3912
        flags_some_set |= flags;
3922
3922
    DBUG_PRINT("info", ("thd->variables.binlog_format: %ld",
3923
3923
                        thd->variables.binlog_format));
3924
3924
    DBUG_PRINT("info", ("multi_engine: %s",
3925
 
                        multi_engine ? "TRUE" : "FALSE"));
 
3925
                        multi_engine ? "true" : "false"));
3926
3926
 
3927
3927
    int error= 0;
3928
3928
    if (flags_all_set == 0)
3998
3998
    thd                 Thread handler
3999
3999
    tables              Tables to lock
4000
4000
    count               Number of opened tables
4001
 
    need_reopen         Out parameter which if TRUE indicates that some
 
4001
    need_reopen         Out parameter which if true indicates that some
4002
4002
                        tables were dropped or altered during this call
4003
4003
                        and therefore invoker should reopen tables and
4004
4004
                        try to lock them once again (in this case
4027
4027
    We can't meet statement requiring prelocking if we already
4028
4028
    in prelocked mode.
4029
4029
  */
4030
 
  *need_reopen= FALSE;
 
4030
  *need_reopen= false;
4031
4031
 
4032
4032
  if (!tables)
4033
4033
    DBUG_RETURN(decide_logging_format(thd, tables));
4307
4307
    item_name                   name of item if it will be created (VIEW)
4308
4308
    ref                         expression substituted in VIEW should be passed
4309
4309
                                using this reference (return view_ref_found)
4310
 
    register_tree_change        TRUE if ref is not stack variable and we
 
4310
    register_tree_change        true if ref is not stack variable and we
4311
4311
                                need register changes in item tree
4312
4312
 
4313
4313
  RETURN
4378
4378
    length               [in]  length of name
4379
4379
    ref                  [in/out] if 'name' is resolved to a view field, ref is
4380
4380
                               set to point to the found view field
4381
 
    register_tree_change [in]  TRUE if ref is not stack variable and we
 
4381
    register_tree_change [in]  true if ref is not stack variable and we
4382
4382
                               need register changes in item tree
4383
4383
    actual_table         [out] the original table reference where the field
4384
4384
                               belongs - differs from 'table_list' only for
4574
4574
    allow_rowid            [in]  do allow finding of "_rowid" field?
4575
4575
    cached_field_index_ptr [in]  cached position in field list (used to
4576
4576
                                 speedup lookup for fields in prepared tables)
4577
 
    register_tree_change   [in]  TRUE if ref is not stack variable and we
 
4577
    register_tree_change   [in]  true if ref is not stack variable and we
4578
4578
                                 need register changes in item tree
4579
4579
    actual_table           [out] the original table reference where the field
4580
4580
                                 belongs - differs from 'table_list' only for
4802
4802
                            except when non-unique fields were found
4803
4803
                          - REPORT_ALL_ERRORS
4804
4804
    check_privileges      need to check privileges
4805
 
    register_tree_change  TRUE if ref is not a stack variable and we
 
4805
    register_tree_change  true if ref is not a stack variable and we
4806
4806
                          to need register changes in item tree
4807
4807
 
4808
4808
  RETURN VALUES
4859
4859
      */
4860
4860
    if (table_ref->table)
4861
4861
      found= find_field_in_table(thd, table_ref->table, name, length,
4862
 
                                 TRUE, &(item->cached_field_index));
 
4862
                                 true, &(item->cached_field_index));
4863
4863
    else
4864
4864
      found= find_field_in_table_ref(thd, table_ref, name, length, item->name,
4865
4865
                                     NULL, NULL, ref, check_privileges,
4866
 
                                     TRUE, &(item->cached_field_index),
 
4866
                                     true, &(item->cached_field_index),
4867
4867
                                     register_tree_change,
4868
4868
                                     &actual_table);
4869
4869
    if (found)
5271
5271
    the list contains the same string.
5272
5272
 
5273
5273
  RETURN
5274
 
    TRUE  if find is in str_list
5275
 
    FALSE otherwise
 
5274
    true  if find is in str_list
 
5275
    false otherwise
5276
5276
*/
5277
5277
 
5278
5278
static bool
5286
5286
    if (find_length != curr_str->length())
5287
5287
      continue;
5288
5288
    if (!my_strcasecmp(system_charset_info, find, curr_str->ptr()))
5289
 
      return TRUE;
 
5289
      return true;
5290
5290
  }
5291
 
  return FALSE;
 
5291
  return false;
5292
5292
}
5293
5293
 
5294
5294
 
5307
5307
    is resolved only the supplied 'table_ref'.
5308
5308
 
5309
5309
  RETURN
5310
 
    FALSE  if all OK
5311
 
    TRUE   otherwise
 
5310
    false  if all OK
 
5311
    true   otherwise
5312
5312
*/
5313
5313
 
5314
5314
static bool
5316
5316
{
5317
5317
  Name_resolution_context *context;
5318
5318
  if (!(context= new (thd->mem_root) Name_resolution_context))
5319
 
    return TRUE;
 
5319
    return true;
5320
5320
  context->init();
5321
5321
  context->first_name_resolution_table=
5322
5322
    context->last_name_resolution_table= table_ref;
5323
5323
  item->context= context;
5324
 
  return FALSE;
 
5324
  return false;
5325
5325
}
5326
5326
 
5327
5327
 
5352
5352
    called for the previous level of NATURAL/USING joins.
5353
5353
 
5354
5354
  RETURN
5355
 
    TRUE   error when some common column is non-unique, or out of memory
5356
 
    FALSE  OK
 
5355
    true   error when some common column is non-unique, or out of memory
 
5356
    false  OK
5357
5357
*/
5358
5358
 
5359
5359
static bool
5362
5362
{
5363
5363
  Field_iterator_table_ref it_1, it_2;
5364
5364
  Natural_join_column *nj_col_1, *nj_col_2;
5365
 
  bool result= TRUE;
5366
 
  bool first_outer_loop= TRUE;
 
5365
  bool result= true;
 
5366
  bool first_outer_loop= true;
5367
5367
  /*
5368
5368
    Leaf table references to which new natural join columns are added
5369
5369
    if the leaves are != NULL.
5383
5383
 
5384
5384
  for (it_1.set(table_ref_1); !it_1.end_of_fields(); it_1.next())
5385
5385
  {
5386
 
    bool found= FALSE;
 
5386
    bool found= false;
5387
5387
    const char *field_name_1;
5388
5388
    /* true if field_name_1 is a member of using_fields */
5389
5389
    bool is_using_column_1;
5419
5419
      /*
5420
5420
        Compare the two columns and check for duplicate common fields.
5421
5421
        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
 
5422
        table_ref_2 (then found == true), or if a field in table_ref_2
5423
5423
        was already matched by some previous field in table_ref_1
5424
 
        (then cur_nj_col_2->is_common == TRUE).
 
5424
        (then cur_nj_col_2->is_common == true).
5425
5425
        Note that it is too early to check the columns outside of the
5426
5426
        USING list for ambiguity because they are not actually "referenced"
5427
5427
        here. These columns must be checked only on unqualified reference 
5437
5437
          goto err;
5438
5438
        }
5439
5439
        nj_col_2= cur_nj_col_2;
5440
 
        found= TRUE;
 
5440
        found= true;
5441
5441
      }
5442
5442
    }
5443
5443
    if (first_outer_loop && leaf_2)
5446
5446
        Make sure that the next inner loop "knows" that all columns
5447
5447
        are materialized already.
5448
5448
      */
5449
 
      leaf_2->is_join_columns_complete= TRUE;
5450
 
      first_outer_loop= FALSE;
 
5449
      leaf_2->is_join_columns_complete= true;
 
5450
      first_outer_loop= false;
5451
5451
    }
5452
5452
    if (!found)
5453
5453
      continue;                                 // No matching field
5511
5511
                   table_ref_1 : table_ref_2),
5512
5512
                  eq_cond);
5513
5513
 
5514
 
      nj_col_1->is_common= nj_col_2->is_common= TRUE;
 
5514
      nj_col_1->is_common= nj_col_2->is_common= true;
5515
5515
      DBUG_PRINT ("info", ("%s.%s and %s.%s are common", 
5516
5516
                           nj_col_1->table_name() ? 
5517
5517
                             nj_col_1->table_name() : "", 
5542
5542
    }
5543
5543
  }
5544
5544
  if (leaf_1)
5545
 
    leaf_1->is_join_columns_complete= TRUE;
 
5545
    leaf_1->is_join_columns_complete= true;
5546
5546
 
5547
5547
  /*
5548
5548
    Everything is OK.
5551
5551
    we check for this error in store_natural_using_join_columns() when
5552
5552
    (found_using_fields < length(join_using_fields)).
5553
5553
  */
5554
 
  result= FALSE;
 
5554
  result= false;
5555
5555
 
5556
5556
err:
5557
5557
  DBUG_RETURN(result);
5590
5590
    for the join that is being processed.
5591
5591
 
5592
5592
  RETURN
5593
 
    TRUE    error: Some common column is ambiguous
5594
 
    FALSE   OK
 
5593
    true    error: Some common column is ambiguous
 
5594
    false   OK
5595
5595
*/
5596
5596
 
5597
5597
static bool
5603
5603
{
5604
5604
  Field_iterator_table_ref it_1, it_2;
5605
5605
  Natural_join_column *nj_col_1, *nj_col_2;
5606
 
  bool result= TRUE;
 
5606
  bool result= true;
5607
5607
  List<Natural_join_column> *non_join_columns;
5608
5608
  DBUG_ENTER("store_natural_using_join_columns");
5609
5609
 
5621
5621
    {
5622
5622
      natural_using_join->join_columns->push_back(nj_col_1);
5623
5623
      /* Reset the common columns for the next call to mark_common_columns. */
5624
 
      nj_col_1->is_common= FALSE;
 
5624
      nj_col_1->is_common= false;
5625
5625
    }
5626
5626
    else
5627
5627
      non_join_columns->push_back(nj_col_1);
5668
5668
    else
5669
5669
    {
5670
5670
      /* Reset the common columns for the next call to mark_common_columns. */
5671
 
      nj_col_2->is_common= FALSE;
 
5671
      nj_col_2->is_common= false;
5672
5672
    }
5673
5673
  }
5674
5674
 
5675
5675
  if (non_join_columns->elements > 0)
5676
5676
    natural_using_join->join_columns->concat(non_join_columns);
5677
 
  natural_using_join->is_join_columns_complete= TRUE;
 
5677
  natural_using_join->is_join_columns_complete= true;
5678
5678
 
5679
 
  result= FALSE;
 
5679
  result= false;
5680
5680
 
5681
5681
err:
5682
5682
  DBUG_RETURN(result);
5709
5709
    from the right to the left in the FROM clause.
5710
5710
 
5711
5711
  RETURN
5712
 
    TRUE   Error
5713
 
    FALSE  OK
 
5712
    true   Error
 
5713
    false  OK
5714
5714
*/
5715
5715
 
5716
5716
static bool
5718
5718
                             TABLE_LIST *left_neighbor,
5719
5719
                             TABLE_LIST *right_neighbor)
5720
5720
{
5721
 
  bool result= TRUE;
 
5721
  bool result= true;
5722
5722
 
5723
5723
  DBUG_ENTER("store_top_level_join_columns");
5724
5724
 
5820
5820
    */
5821
5821
    table_ref_1->natural_join= table_ref_2->natural_join= NULL;
5822
5822
 
5823
 
    /* Add a TRUE condition to outer joins that have no common columns. */
 
5823
    /* Add a true condition to outer joins that have no common columns. */
5824
5824
    if (table_ref_2->outer_join &&
5825
5825
        !table_ref_1->on_expr && !table_ref_2->on_expr)
5826
5826
      table_ref_2->on_expr= new Item_int((longlong) 1,1);   /* Always true. */
5841
5841
    else
5842
5842
      table_ref->next_name_resolution_table= NULL;
5843
5843
  }
5844
 
  result= FALSE; /* All is OK. */
 
5844
  result= false; /* All is OK. */
5845
5845
 
5846
5846
err:
5847
5847
  DBUG_RETURN(result);
5869
5869
    to the left in the FROM clause.
5870
5870
 
5871
5871
  RETURN
5872
 
    TRUE   Error
5873
 
    FALSE  OK
 
5872
    true   Error
 
5873
    false  OK
5874
5874
*/
5875
5875
static bool setup_natural_join_row_types(THD *thd,
5876
5876
                                         List<TABLE_LIST> *from_clause,
5878
5878
{
5879
5879
  thd->where= "from clause";
5880
5880
  if (from_clause->elements == 0)
5881
 
    return FALSE; /* We come here in the case of UNIONs. */
 
5881
    return false; /* We come here in the case of UNIONs. */
5882
5882
 
5883
5883
  List_iterator_fast<TABLE_LIST> table_ref_it(*from_clause);
5884
5884
  TABLE_LIST *table_ref; /* Current table reference. */
5897
5897
    {
5898
5898
      if (store_top_level_join_columns(thd, table_ref,
5899
5899
                                       left_neighbor, right_neighbor))
5900
 
        return TRUE;
 
5900
        return true;
5901
5901
      if (left_neighbor)
5902
5902
      {
5903
5903
        TABLE_LIST *first_leaf_on_the_right;
5918
5918
  context->first_name_resolution_table=
5919
5919
    right_neighbor->first_leaf_for_name_resolution();
5920
5920
 
5921
 
  return FALSE;
 
5921
  return false;
5922
5922
}
5923
5923
 
5924
5924
 
6031
6031
      thd->lex->allow_sum_func= save_allow_sum_func;
6032
6032
      thd->mark_used_columns= save_mark_used_columns;
6033
6033
      DBUG_PRINT("info", ("thd->mark_used_columns: %d", thd->mark_used_columns));
6034
 
      DBUG_RETURN(TRUE); /* purecov: inspected */
 
6034
      DBUG_RETURN(true); /* purecov: inspected */
6035
6035
    }
6036
6036
    if (ref)
6037
6037
      *(ref++)= item;
6098
6098
    table->map is not set and all Item_field will be regarded as const items.
6099
6099
 
6100
6100
  RETURN
6101
 
    FALSE ok;  In this case *map will includes the chosen index
6102
 
    TRUE  error
 
6101
    false ok;  In this case *map will includes the chosen index
 
6102
    true  error
6103
6103
*/
6104
6104
 
6105
6105
bool setup_tables(THD *thd, Name_resolution_context *context,
6173
6173
    table leaves list for access to all the tables that belong to a view
6174
6174
 
6175
6175
  RETURN
6176
 
    FALSE ok;  In this case *map will include the chosen index
6177
 
    TRUE  error
 
6176
    false ok;  In this case *map will include the chosen index
 
6177
    true  error
6178
6178
*/
6179
6179
bool setup_tables_and_check_access(THD *thd, 
6180
6180
                                   Name_resolution_context *context,
6188
6188
 
6189
6189
  if (setup_tables(thd, context, from_clause, tables,
6190
6190
                   &leaves_tmp, select_insert))
6191
 
    return TRUE;
 
6191
    return true;
6192
6192
 
6193
6193
  if (leaves)
6194
6194
    *leaves= leaves_tmp;
6197
6197
  {
6198
6198
    if (leaves_tmp->belong_to_view)
6199
6199
    {
6200
 
      return TRUE;
 
6200
      return true;
6201
6201
    }
6202
6202
    first_table= 0;
6203
6203
  }
6204
 
  return FALSE;
 
6204
  return false;
6205
6205
}
6206
6206
 
6207
6207
 
6285
6285
    db_name= name_buff;
6286
6286
  }
6287
6287
 
6288
 
  found= FALSE;
 
6288
  found= false;
6289
6289
 
6290
6290
  /*
6291
6291
    If table names are qualified, then loop over all tables used in the query,
6328
6328
      Item *item;
6329
6329
 
6330
6330
      if (!(item= field_iterator.create_item(thd)))
6331
 
        DBUG_RETURN(TRUE);
 
6331
        DBUG_RETURN(true);
6332
6332
 
6333
6333
      if (!found)
6334
6334
      {
6335
 
        found= TRUE;
 
6335
        found= true;
6336
6336
        it->replace(item); /* Replace '*' with the first found item. */
6337
6337
      }
6338
6338
      else
6356
6356
          */
6357
6357
          Natural_join_column *nj_col;
6358
6358
          if (!(nj_col= field_iterator.get_natural_column_ref()))
6359
 
            DBUG_RETURN(TRUE);
 
6359
            DBUG_RETURN(true);
6360
6360
          DBUG_ASSERT(nj_col->table_field);
6361
6361
          field_table= nj_col->table_ref->table;
6362
6362
          if (field_table)
6382
6382
      table->used_fields= table->s->fields;
6383
6383
  }
6384
6384
  if (found)
6385
 
    DBUG_RETURN(FALSE);
 
6385
    DBUG_RETURN(false);
6386
6386
 
6387
6387
  /*
6388
6388
    TODO: in the case when we skipped all columns because there was a
6394
6394
  else
6395
6395
    my_error(ER_BAD_TABLE_ERROR, MYF(0), table_name);
6396
6396
 
6397
 
  DBUG_RETURN(TRUE);
 
6397
  DBUG_RETURN(true);
6398
6398
}
6399
6399
 
6400
6400
 
6412
6412
    TODO
6413
6413
 
6414
6414
  RETURN
6415
 
    TRUE  if some error occured (e.g. out of memory)
6416
 
    FALSE if all is OK
 
6415
    true  if some error occured (e.g. out of memory)
 
6416
    false if all is OK
6417
6417
*/
6418
6418
 
6419
6419
int setup_conds(THD *thd, TABLE_LIST *tables, TABLE_LIST *leaves,
6423
6423
  TABLE_LIST *table= NULL;      // For HP compilers
6424
6424
  void *save_thd_marker= thd->thd_marker;
6425
6425
  /*
6426
 
    it_is_update set to TRUE when tables of primary SELECT_LEX (SELECT_LEX
 
6426
    it_is_update set to true when tables of primary SELECT_LEX (SELECT_LEX
6427
6427
    which belong to LEX, i.e. most up SELECT) will be updated by
6428
6428
    INSERT/UPDATE/LOAD
6429
6429
    NOTE: using this condition helps to prevent call of prepare_check_option()
6502
6502
    thd           thread handler
6503
6503
    fields        Item_fields list to be filled
6504
6504
    values        values to fill with
6505
 
    ignore_errors TRUE if we should ignore errors
 
6505
    ignore_errors true if we should ignore errors
6506
6506
 
6507
6507
  NOTE
6508
6508
    fill_record() may set table->auto_increment_field_not_null and a
6510
6510
    function.
6511
6511
 
6512
6512
  RETURN
6513
 
    FALSE   OK
6514
 
    TRUE    error occured
 
6513
    false   OK
 
6514
    true    error occured
6515
6515
*/
6516
6516
 
6517
6517
bool
6540
6540
      goto err;
6541
6541
    }
6542
6542
    table= field->field->table;
6543
 
    table->auto_increment_field_not_null= FALSE;
 
6543
    table->auto_increment_field_not_null= false;
6544
6544
    f.rewind();
6545
6545
  }
6546
6546
  while ((fld= f++))
6554
6554
    Field *rfield= field->field;
6555
6555
    table= rfield->table;
6556
6556
    if (rfield == table->next_number_field)
6557
 
      table->auto_increment_field_not_null= TRUE;
 
6557
      table->auto_increment_field_not_null= true;
6558
6558
    if ((value->save_in_field(rfield, 0) < 0) && !ignore_errors)
6559
6559
    {
6560
6560
      my_message(ER_UNKNOWN_ERROR, ER(ER_UNKNOWN_ERROR), MYF(0));
6564
6564
  DBUG_RETURN(thd->is_error());
6565
6565
err:
6566
6566
  if (table)
6567
 
    table->auto_increment_field_not_null= FALSE;
6568
 
  DBUG_RETURN(TRUE);
 
6567
    table->auto_increment_field_not_null= false;
 
6568
  DBUG_RETURN(true);
6569
6569
}
6570
6570
 
6571
6571
 
6577
6577
    thd           thread handler
6578
6578
    ptr           pointer on pointer to record
6579
6579
    values        list of fields
6580
 
    ignore_errors TRUE if we should ignore errors
 
6580
    ignore_errors true if we should ignore errors
6581
6581
 
6582
6582
  NOTE
6583
6583
    fill_record() may set table->auto_increment_field_not_null and a
6585
6585
    function.
6586
6586
 
6587
6587
  RETURN
6588
 
    FALSE   OK
6589
 
    TRUE    error occured
 
6588
    false   OK
 
6589
    true    error occured
6590
6590
*/
6591
6591
 
6592
6592
bool
6609
6609
      thus we safely can take table from the first field.
6610
6610
    */
6611
6611
    table= (*ptr)->table;
6612
 
    table->auto_increment_field_not_null= FALSE;
 
6612
    table->auto_increment_field_not_null= false;
6613
6613
  }
6614
6614
  while ((field = *ptr++) && ! thd->is_error())
6615
6615
  {
6616
6616
    value=v++;
6617
6617
    table= field->table;
6618
6618
    if (field == table->next_number_field)
6619
 
      table->auto_increment_field_not_null= TRUE;
 
6619
      table->auto_increment_field_not_null= true;
6620
6620
    if (value->save_in_field(field, 0) < 0)
6621
6621
      goto err;
6622
6622
  }
6624
6624
 
6625
6625
err:
6626
6626
  if (table)
6627
 
    table->auto_increment_field_not_null= FALSE;
6628
 
  DBUG_RETURN(TRUE);
 
6627
    table->auto_increment_field_not_null= false;
 
6628
  DBUG_RETURN(true);
6629
6629
}
6630
6630
 
6631
6631
 
6939
6939
    with this call.
6940
6940
 
6941
6941
  RETURN
6942
 
    FALSE   Success
6943
 
    TRUE    Error
 
6942
    false   Success
 
6943
    true    Error
6944
6944
*/
6945
6945
 
6946
6946
bool
6978
6978
                                 MYSQL_LOCK_IGNORE_FLUSH, &not_used);
6979
6979
  }
6980
6980
  if (thd->lock)
6981
 
    DBUG_RETURN(FALSE);
 
6981
    DBUG_RETURN(false);
6982
6982
 
6983
6983
error:
6984
6984
  close_system_tables(thd, backup);
6985
6985
 
6986
 
  DBUG_RETURN(TRUE);
 
6986
  DBUG_RETURN(true);
6987
6987
}
6988
6988
 
6989
6989