~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/sql_base.cc

  • Committer: Eric Herman
  • Date: 2008-12-06 19:42:46 UTC
  • mto: (656.1.6 devel)
  • mto: This revision was merged to the branch mainline in revision 665.
  • Revision ID: eric@mysql.com-20081206194246-5cdexuu81i366eek
removed trailing whitespace with simple script:

for file in $(find . -name "*.c") $(find . -name "*.cc") $(find . -name "*.h"); do ruby -pe 'gsub(/\s+$/, $/)' < $file > $file.out; mv $file.out $file; done;

Show diffs side-by-side

added added

removed removed

Lines of Context:
284
284
  return(share);
285
285
 
286
286
found:
287
 
  /* 
 
287
  /*
288
288
     We found an existing table definition. Return it if we didn't get
289
289
     an error when reading the table definition from file.
290
290
  */
346
346
 
347
347
    If share is NULL, and there is no error, we're inside
348
348
    pre-locking, which silences 'ER_NO_SUCH_TABLE' errors
349
 
    with the intention to silently drop non-existing tables 
 
349
    with the intention to silently drop non-existing tables
350
350
    from the pre-locking list. In this case we still need to try
351
351
    auto-discover before returning a NULL share.
352
352
 
353
353
    If share is NULL and the error is ER_NO_SUCH_TABLE, this is
354
 
    the same as above, only that the error was not silenced by 
 
354
    the same as above, only that the error was not silenced by
355
355
    pre-locking. Once again, we need to try to auto-discover
356
356
    the share.
357
357
 
387
387
}
388
388
 
389
389
 
390
 
/* 
 
390
/*
391
391
   Mark that we are not using table share anymore.
392
392
 
393
393
   SYNOPSIS
469
469
  table_list.table_name= (char*) table_name;
470
470
  key_length= create_table_def_key((Session*) 0, key, &table_list, 0);
471
471
  return (TABLE_SHARE*) hash_search(&table_def_cache,(unsigned char*) key, key_length);
472
 
}  
 
472
}
473
473
 
474
474
 
475
475
/*
882
882
    tmp.table_name= share->table_name.str;
883
883
    tmp.next_local= tables;
884
884
 
885
 
    tables= (TableList *) memdup_root(session->mem_root, (char*)&tmp, 
 
885
    tables= (TableList *) memdup_root(session->mem_root, (char*)&tmp,
886
886
                                       sizeof(TableList));
887
887
  }
888
888
 
1159
1159
 
1160
1160
/*
1161
1161
  Close all temporary tables created by 'CREATE TEMPORARY TABLE' for thread
1162
 
  creates one DROP TEMPORARY Table binlog event for each pseudo-thread 
 
1162
  creates one DROP TEMPORARY Table binlog event for each pseudo-thread
1163
1163
*/
1164
1164
 
1165
1165
void close_temporary_tables(Session *session)
1735
1735
     wait_for_condition()
1736
1736
     session    Thread handler
1737
1737
     mutex      mutex that is currently hold that is associated with condition
1738
 
                Will be unlocked on return     
 
1738
                Will be unlocked on return
1739
1739
     cond       Condition to wait for
1740
1740
*/
1741
1741
 
1760
1760
    condition variables that are guranteed to not disapper (freed) even if this
1761
1761
    mutex is unlocked
1762
1762
  */
1763
 
    
 
1763
 
1764
1764
  pthread_mutex_unlock(mutex);
1765
1765
  pthread_mutex_lock(&session->mysys_var->mutex);
1766
1766
  session->mysys_var->current_mutex= 0;
2316
2316
      need to back off and re-start opening tables.
2317
2317
      If we do not back off now, we may dead lock in case of lock
2318
2318
      order mismatch with some other thread:
2319
 
      c1: name lock t1; -- sort of exclusive lock 
 
2319
      c1: name lock t1; -- sort of exclusive lock
2320
2320
      c2: open t2;      -- sort of shared lock
2321
2321
      c1: name lock t2; -- blocks
2322
2322
      c2: open t1; -- blocks
3123
3123
  safe_mutex_assert_owner(&LOCK_open);
3124
3124
retry:
3125
3125
  if (!(share= get_table_share_with_create(session, table_list, cache_key,
3126
 
                                           cache_key_length, 
 
3126
                                           cache_key_length,
3127
3127
                                           table_list->i_s_requested_object,
3128
3128
                                           &error)))
3129
3129
    return(1);
3147
3147
        Here we should wait until all threads has released the table.
3148
3148
        For now we do one retry. This may cause a deadlock if there
3149
3149
        is other threads waiting for other tables used by this thread.
3150
 
        
 
3150
 
3151
3151
        Proper fix would be to if the second retry failed:
3152
3152
        - Mark that table def changed
3153
3153
        - Return from open table
3213
3213
       session->clear_error();                  // Clear error message
3214
3214
     pthread_mutex_lock(&LOCK_open);
3215
3215
     unlock_table_name(session, table_list);
3216
 
 
 
3216
 
3217
3217
     if (error)
3218
3218
       goto err;
3219
3219
     break;
3505
3505
  RETURN VALUES
3506
3506
    table               Opened table
3507
3507
    0                   Error
3508
 
  
 
3508
 
3509
3509
    If ok, the following are also set:
3510
3510
      table_list->lock_type     lock_type
3511
3511
      table_list->table         table
3576
3576
  uint32_t counter;
3577
3577
  bool need_reopen;
3578
3578
 
3579
 
  for ( ; ; ) 
 
3579
  for ( ; ; )
3580
3580
  {
3581
3581
    if (open_tables(session, &tables, &counter, 0))
3582
3582
      return(-1);
3611
3611
    false - ok
3612
3612
    true  - error
3613
3613
 
3614
 
  NOTE 
 
3614
  NOTE
3615
3615
    This is to be used on prepare stage when you don't read any
3616
3616
    data from the tables.
3617
3617
*/
3868
3868
 
3869
3869
/* Special Field pointers as return values of find_field_in_XXX functions. */
3870
3870
Field *not_found_field= (Field*) 0x1;
3871
 
Field *view_ref_found= (Field*) 0x2; 
 
3871
Field *view_ref_found= (Field*) 0x2;
3872
3872
 
3873
3873
#define WRONG_GRANT (Field*) -1
3874
3874
 
3882
3882
      We always want to register the used keys, as the column bitmap may have
3883
3883
      been set for all fields (for example for view).
3884
3884
    */
3885
 
      
 
3885
 
3886
3886
    table->covering_keys.intersect(field->part_of_key);
3887
3887
    table->merge_keys.merge(field->part_of_key);
3888
3888
 
3956
3956
  assert(table_ref->is_natural_join && table_ref->join_columns);
3957
3957
  assert(*actual_table == NULL);
3958
3958
 
3959
 
  for (nj_col= NULL, curr_nj_col= field_it++; curr_nj_col; 
 
3959
  for (nj_col= NULL, curr_nj_col= field_it++; curr_nj_col;
3960
3960
       curr_nj_col= field_it++)
3961
3961
  {
3962
3962
    if (!my_strcasecmp(system_charset_info, curr_nj_col->name(), name))
3979
3979
  }
3980
3980
 
3981
3981
  *actual_table= nj_col->table_ref;
3982
 
  
 
3982
 
3983
3983
  return(found_field);
3984
3984
}
3985
3985
 
4045
4045
        Item *vcol_item= (*field_ptr)->vcol_info->expr_item;
4046
4046
        assert(vcol_item);
4047
4047
        vcol_item->walk(&Item::register_field_in_read_map, 1, (unsigned char *) 0);
4048
 
        /* 
4049
 
          Set the virtual field for write here if 
 
4048
        /*
 
4049
          Set the virtual field for write here if
4050
4050
          1) this procedure is called for a read-only operation (SELECT), and
4051
4051
          2) the virtual column is not phycically stored in the table
4052
4052
        */
4053
 
        if ((session->mark_used_columns != MARK_COLUMNS_WRITE) && 
 
4053
        if ((session->mark_used_columns != MARK_COLUMNS_WRITE) &&
4054
4054
            (not (*field_ptr)->is_stored))
4055
4055
          bitmap_set_bit((*field_ptr)->table->write_set, (*field_ptr)->field_index);
4056
4056
      }
4536
4536
                                return not_found_item, report other errors,
4537
4537
                                return 0
4538
4538
      IGNORE_ERRORS             Do not report errors, return 0 if error
4539
 
    resolution                  Set to the resolution type if the item is found 
4540
 
                                (it says whether the item is resolved 
 
4539
    resolution                  Set to the resolution type if the item is found
 
4540
                                (it says whether the item is resolved
4541
4541
                                 against an alias name,
4542
4542
                                 or as a field name without alias,
4543
4543
                                 or as a field hidden by alias,
4544
4544
                                 or ignoring alias)
4545
 
                                
 
4545
 
4546
4546
  RETURN VALUES
4547
4547
    0                   Item is not found or item is not unique,
4548
4548
                        error message is reported
4576
4576
 
4577
4577
  *resolution= NOT_RESOLVED;
4578
4578
 
4579
 
  is_ref_by_name= (find->type() == Item::FIELD_ITEM  || 
 
4579
  is_ref_by_name= (find->type() == Item::FIELD_ITEM  ||
4580
4580
                   find->type() == Item::REF_ITEM);
4581
4581
  if (is_ref_by_name)
4582
4582
  {
4593
4593
 
4594
4594
      /*
4595
4595
        In case of group_concat() with ORDER BY condition in the QUERY
4596
 
        item_field can be field of temporary table without item name 
 
4596
        item_field can be field of temporary table without item name
4597
4597
        (if this field created from expression argument of group_concat()),
4598
4598
        => we have to check presence of name before compare
4599
 
      */ 
 
4599
      */
4600
4600
      if (!item_field->name)
4601
4601
        continue;
4602
4602
 
4621
4621
        if (item_field->field_name && item_field->table_name &&
4622
4622
            !my_strcasecmp(system_charset_info, item_field->field_name,
4623
4623
                           field_name) &&
4624
 
            !my_strcasecmp(table_alias_charset, item_field->table_name, 
 
4624
            !my_strcasecmp(table_alias_charset, item_field->table_name,
4625
4625
                           table_name) &&
4626
4626
            (!db_name || (item_field->db_name &&
4627
4627
                          !strcmp(item_field->db_name, db_name))))
4696
4696
      }
4697
4697
    }
4698
4698
    else if (!table_name)
4699
 
    { 
 
4699
    {
4700
4700
      if (is_ref_by_name && find->name && item->name &&
4701
4701
          !my_strcasecmp(system_charset_info,item->name,find->name))
4702
4702
      {
4872
4872
    if (!(nj_col_1= it_1.get_or_create_column_ref(leaf_1)))
4873
4873
      goto err;
4874
4874
    field_name_1= nj_col_1->name();
4875
 
    is_using_column_1= using_fields && 
 
4875
    is_using_column_1= using_fields &&
4876
4876
      test_if_string_in_list(field_name_1, using_fields);
4877
4877
 
4878
4878
    /*
4899
4899
        (then cur_nj_col_2->is_common == true).
4900
4900
        Note that it is too early to check the columns outside of the
4901
4901
        USING list for ambiguity because they are not actually "referenced"
4902
 
        here. These columns must be checked only on unqualified reference 
 
4902
        here. These columns must be checked only on unqualified reference
4903
4903
        by name (e.g. in SELECT list).
4904
4904
      */
4905
4905
      if (!my_strcasecmp(system_charset_info, field_name_1, cur_field_name_2))
5561
5561
{
5562
5562
  uint32_t tablenr= 0;
5563
5563
 
5564
 
  assert ((select_insert && !tables->next_name_resolution_table) || !tables || 
 
5564
  assert ((select_insert && !tables->next_name_resolution_table) || !tables ||
5565
5565
               (context->table_list && context->first_name_resolution_table));
5566
5566
  /*
5567
5567
    this is used for INSERT ... SELECT.
5628
5628
    false ok;  In this case *map will include the chosen index
5629
5629
    true  error
5630
5630
*/
5631
 
bool setup_tables_and_check_access(Session *session, 
 
5631
bool setup_tables_and_check_access(Session *session,
5632
5632
                                   Name_resolution_context *context,
5633
5633
                                   List<TableList> *from_clause,
5634
5634
                                   TableList *tables,
5751
5751
 
5752
5752
    assert(tables->is_leaf_for_name_resolution());
5753
5753
 
5754
 
    if ((table_name && my_strcasecmp(table_alias_charset, table_name, tables->alias)) || 
 
5754
    if ((table_name && my_strcasecmp(table_alias_charset, table_name, tables->alias)) ||
5755
5755
        (db_name && strcmp(tables->db,db_name)))
5756
5756
      continue;
5757
5757
 
6014
6014
    table= rfield->table;
6015
6015
    if (rfield == table->next_number_field)
6016
6016
      table->auto_increment_field_not_null= true;
6017
 
    if (rfield->vcol_info && 
6018
 
        value->type() != Item::DEFAULT_VALUE_ITEM && 
 
6017
    if (rfield->vcol_info &&
 
6018
        value->type() != Item::DEFAULT_VALUE_ITEM &&
6019
6019
        value->type() != Item::NULL_ITEM &&
6020
6020
        table->s->table_category != TABLE_CATEGORY_TEMPORARY)
6021
6021
    {
6042
6042
    while ((table= t++))
6043
6043
    {
6044
6044
      /*
6045
 
        Do simple optimization to prevent unnecessary re-generating 
 
6045
        Do simple optimization to prevent unnecessary re-generating
6046
6046
        values for virtual fields
6047
6047
      */
6048
6048
      if (table != prev_table)
6096
6096
  Field *field;
6097
6097
  List<Table> tbl_list;
6098
6098
  bool abort_on_warning_saved= session->abort_on_warning;
6099
 
  
 
6099
 
6100
6100
  tbl_list.empty();
6101
6101
  /*
6102
6102
    Reset the table->auto_increment_field_not_null as it is valid for
6117
6117
    table= field->table;
6118
6118
    if (field == table->next_number_field)
6119
6119
      table->auto_increment_field_not_null= true;
6120
 
    if (field->vcol_info && 
6121
 
        value->type() != Item::DEFAULT_VALUE_ITEM && 
 
6120
    if (field->vcol_info &&
 
6121
        value->type() != Item::DEFAULT_VALUE_ITEM &&
6122
6122
        value->type() != Item::NULL_ITEM &&
6123
6123
        table->s->table_category != TABLE_CATEGORY_TEMPORARY)
6124
6124
    {
6142
6142
    while ((table= t++))
6143
6143
    {
6144
6144
      /*
6145
 
        Do simple optimization to prevent unnecessary re-generating 
 
6145
        Do simple optimization to prevent unnecessary re-generating
6146
6146
        values for virtual fields
6147
6147
      */
6148
6148
      if (table != prev_table)
6229
6229
          So we hide error messages which happnes during deleting of these
6230
6230
          files(MYF(0)).
6231
6231
        */
6232
 
        my_delete(filePath, MYF(0)); 
 
6232
        my_delete(filePath, MYF(0));
6233
6233
      }
6234
6234
    }
6235
6235
    my_dirend(dirp);