~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/table.cc

  • Committer: Brian Aker
  • Date: 2010-06-15 13:37:26 UTC
  • Revision ID: brian@gaz-20100615133726-160z0ql8gxi8s3rg
This is a rollup set of patches for modifications to TableIdentifier to have
a getKey() which is now used for open_cache and table_share_def cache. This
also includes additional unittests on TableIdentifier, and makes use of some
cleanup, though not perfect, to TableShare for its contructors.

Show diffs side-by-side

added added

removed removed

Lines of Context:
473
473
{
474
474
 
475
475
  if ((cursor->getEngine()->check_flag(HTON_BIT_PRIMARY_KEY_IN_READ_INDEX)) &&
476
 
      s->primary_key < MAX_KEY)
 
476
      s->hasPrimaryKey())
477
477
  {
478
 
    mark_columns_used_by_index_no_reset(s->primary_key);
 
478
    mark_columns_used_by_index_no_reset(s->getPrimaryKey());
479
479
  }
480
480
  return;
481
481
}
593
593
    be able to do an delete
594
594
 
595
595
  */
596
 
  if (s->primary_key == MAX_KEY)
 
596
  if (not s->hasPrimaryKey())
597
597
  {
598
598
    /* fallback to use all columns in the table to identify row */
599
599
    use_all_columns();
600
600
    return;
601
601
  }
602
602
  else
603
 
    mark_columns_used_by_index_no_reset(s->primary_key);
 
603
    mark_columns_used_by_index_no_reset(s->getPrimaryKey());
604
604
 
605
605
  /* If we the engine wants all predicates we mark all keys */
606
606
  if (cursor->getEngine()->check_flag(HTON_BIT_REQUIRES_KEY_COLUMNS_FOR_DELETE))
641
641
    the primary key, the hidden primary key or all columns to be
642
642
    able to do an update
643
643
  */
644
 
  if (s->primary_key == MAX_KEY)
 
644
  if (not s->hasPrimaryKey())
645
645
  {
646
646
    /* fallback to use all columns in the table to identify row */
647
647
    use_all_columns();
648
648
    return;
649
649
  }
650
650
  else
651
 
    mark_columns_used_by_index_no_reset(s->primary_key);
 
651
    mark_columns_used_by_index_no_reset(s->getPrimaryKey());
652
652
 
653
653
  if (cursor->getEngine()->check_flag(HTON_BIT_REQUIRES_KEY_COLUMNS_FOR_DELETE))
654
654
  {
790
790
#define AVG_STRING_LENGTH_TO_PACK_ROWS   64
791
791
#define RATIO_TO_PACK_ROWS             2
792
792
 
793
 
static void make_internal_temporary_table_path(Session *session, char *path)
794
 
{
795
 
  snprintf(path, FN_REFLEN, "%s%lx_%"PRIx64"_%x", TMP_FILE_PREFIX, (unsigned long)current_pid,
796
 
           session->thread_id, session->tmp_table++);
797
 
 
798
 
  internal::fn_format(path, path, drizzle_tmpdir.c_str(), "", MY_REPLACE_EXT|MY_UNPACK_FILENAME);
799
 
}
800
 
 
801
793
Table *
802
794
create_tmp_table(Session *session,Tmp_Table_Param *param,List<Item> &fields,
803
795
                 order_st *group, bool distinct, bool save_sum_fields,
815
807
  bool  using_unique_constraint= false;
816
808
  bool  use_packed_rows= true;
817
809
  bool  not_all_columns= !(select_options & TMP_TABLE_ALL_COLUMNS);
818
 
  char  *tmpname;
819
 
  char  path[FN_REFLEN];
820
810
  unsigned char *pos, *group_buff, *bitmaps;
821
811
  unsigned char *null_flags;
822
812
  Field **reg_field, **from_field, **default_field;
831
821
 
832
822
  status_var_increment(session->status_var.created_tmp_tables);
833
823
 
834
 
  make_internal_temporary_table_path(session, path);
835
 
 
836
824
  if (group)
837
825
  {
838
826
    if (! param->quick_group)
872
860
    copy_func_count+= param->sum_func_count;
873
861
  }
874
862
 
875
 
  if (not session->getMemRoot()->multi_alloc_root(0, &tmpname, (uint32_t) strlen(path)+1, NULL))
876
 
  {
877
 
    return NULL;
878
 
  }
879
 
 
880
 
  strcpy(tmpname, path);
881
 
 
882
 
  TableShareInstance *share= session->getTemporaryShare(tmpname); // This will not go into the tableshare cache, so no key is used.
 
863
  TableShareInstance *share= session->getTemporaryShare(message::Table::INTERNAL); // This will not go into the tableshare cache, so no key is used.
883
864
 
884
865
  if (not share->getMemRoot()->multi_alloc_root(0,
885
866
                                                &default_field, sizeof(Field*) * (field_count),
931
912
  share->blob_ptr_size= portable_sizeof_char_ptr;
932
913
  share->db_low_byte_first=1;                // True for HEAP and MyISAM
933
914
  share->table_charset= param->table_charset;
934
 
  share->primary_key= MAX_KEY;               // Indicate no primary key
935
915
  share->keys_for_keyread.reset();
936
916
  share->keys_in_use.reset();
937
917
 
1484
1464
  unsigned char *bitmaps;
1485
1465
  Table *table;
1486
1466
 
1487
 
  TableShareInstance *share= getTemporaryShare(); // This will not go into the tableshare cache, so no key is used.
 
1467
  TableShareInstance *share= getTemporaryShare(message::Table::INTERNAL); // This will not go into the tableshare cache, so no key is used.
1488
1468
 
1489
1469
  if (! share->getMemRoot()->multi_alloc_root(0,
1490
1470
                                              &bitmaps, bitmap_buffer_size(field_count)*2,
2033
2013
  return false;
2034
2014
}
2035
2015
 
2036
 
/*
2037
 
  Used by ALTER Table when the table is a temporary one. It changes something
2038
 
  only if the ALTER contained a RENAME clause (otherwise, table_name is the old
2039
 
  name).
2040
 
  Prepares a table cache key, which is the concatenation of db, table_name and
2041
 
  session->slave_proxy_id, separated by '\0'.
2042
 
*/
2043
 
 
2044
 
bool Table::renameAlterTemporaryTable(TableIdentifier &identifier)
2045
 
{
2046
 
  char *key;
2047
 
  uint32_t key_length;
2048
 
  TableShare *share= s;
2049
 
 
2050
 
  if (not (key=(char*) share->alloc_root(MAX_DBKEY_LENGTH)))
2051
 
    return true;
2052
 
 
2053
 
  key_length= TableShare::createKey(key, identifier);
2054
 
  share->set_table_cache_key(key, key_length);
2055
 
 
2056
 
  message::Table *message= share->getTableProto();
2057
 
 
2058
 
  message->set_name(identifier.getTableName());
2059
 
  message->set_schema(identifier.getSchemaName());
2060
 
 
2061
 
  return false;
2062
 
}
2063
 
 
2064
2016
} /* namespace drizzled */