~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/table.cc

  • Committer: Brian Aker
  • Date: 2008-08-16 22:34:15 UTC
  • mto: This revision was merged to the branch mainline in revision 346.
  • Revision ID: brian@tangent.org-20080816223415-n24esdpfcqi4pwpy
Refactor around classes. TABLE_LIST has been factored out of table.h

Show diffs side-by-side

added added

removed removed

Lines of Context:
1214
1214
 
1215
1215
int open_table_from_share(THD *thd, TABLE_SHARE *share, const char *alias,
1216
1216
                          uint db_stat, uint prgflag, uint ha_open_flags,
1217
 
                          TABLE *outparam, open_table_mode open_mode)
 
1217
                          Table *outparam, open_table_mode open_mode)
1218
1218
{
1219
1219
  int error;
1220
1220
  uint records, i, bitmap_size;
1461
1461
 
1462
1462
  SYNOPSIS
1463
1463
    closefrm()
1464
 
    table               TABLE object to free
 
1464
    table               Table object to free
1465
1465
    free_share          Is 1 if we also want to free table_share
1466
1466
*/
1467
1467
 
1468
 
int closefrm(register TABLE *table, bool free_share)
 
1468
int closefrm(register Table *table, bool free_share)
1469
1469
{
1470
1470
  int error=0;
1471
1471
 
1495
1495
 
1496
1496
/* Deallocate temporary blob storage */
1497
1497
 
1498
 
void free_blobs(register TABLE *table)
 
1498
void free_blobs(register Table *table)
1499
1499
{
1500
1500
  uint *ptr, *end;
1501
1501
  for (ptr= table->getBlobField(), end=ptr + table->sizeBlobFields();
2134
2134
    given a buffer with a key value, and a map of keyparts
2135
2135
    that are present in this value, returns the length of the value
2136
2136
*/
2137
 
uint calculate_key_len(TABLE *table, uint key,
 
2137
uint calculate_key_len(Table *table, uint key,
2138
2138
                       const uchar *buf __attribute__((unused)),
2139
2139
                       key_part_map keypart_map)
2140
2140
{
2266
2266
*/
2267
2267
 
2268
2268
bool
2269
 
table_check_intact(TABLE *table, const uint table_f_count,
 
2269
table_check_intact(Table *table, const uint table_f_count,
2270
2270
                   const TABLE_FIELD_W_TYPE *table_def)
2271
2271
{
2272
2272
  uint i;
2482
2482
 
2483
2483
/*
2484
2484
  Find underlying base tables (TABLE_LIST) which represent given
2485
 
  table_to_find (TABLE)
 
2485
  table_to_find (Table)
2486
2486
 
2487
2487
  SYNOPSIS
2488
2488
    TABLE_LIST::find_underlying_table()
2493
2493
    found table reference
2494
2494
*/
2495
2495
 
2496
 
TABLE_LIST *TABLE_LIST::find_underlying_table(TABLE *table_to_find)
 
2496
TABLE_LIST *TABLE_LIST::find_underlying_table(Table *table_to_find)
2497
2497
{
2498
2498
  /* is this real table and table which we are looking for? */
2499
2499
  if (table == table_to_find && merge_underlying_list == 0)
3369
3369
 
3370
3370
  SYNOPSIS
3371
3371
    process_index_hints()
3372
 
      table         the TABLE to operate on.
 
3372
      table         the Table to operate on.
3373
3373
 
3374
3374
  DESCRIPTION
3375
3375
    The parser collects the index hints for each table in a "tagged list" 
3415
3415
    false                no errors found
3416
3416
    TRUE                 found and reported an error.
3417
3417
*/
3418
 
bool TABLE_LIST::process_index_hints(TABLE *tbl)
 
3418
bool TABLE_LIST::process_index_hints(Table *tbl)
3419
3419
{
3420
3420
  /* initialize the result variables */
3421
3421
  tbl->keys_in_use_for_query= tbl->keys_in_use_for_group_by= 
3534
3534
}
3535
3535
 
3536
3536
 
3537
 
size_t max_row_length(TABLE *table, const uchar *data)
 
3537
size_t max_row_length(Table *table, const uchar *data)
3538
3538
{
3539
3539
  size_t length= table->getRecordLength() + 2 * table->sizeFields();
3540
3540
  uint *const beg= table->getBlobField();
3550
3550
  return length;
3551
3551
}
3552
3552
 
 
3553
void Field_iterator_table::set(TABLE_LIST *table) 
 
3554
 
3555
  ptr= table->table->field; 
 
3556
}
 
3557
 
 
3558
 
3553
3559
/*
3554
3560
  Check type of .frm if we are not going to parse it
3555
3561
 
3558
3564
  path        path to file
3559
3565
 
3560
3566
  RETURN
3561
 
  FRMTYPE_ERROR       error
3562
 
  FRMTYPE_TABLE       table
 
3567
  false       error
 
3568
  true       table
3563
3569
*/
3564
3570
 
3565
 
frm_type_enum mysql_frm_type(THD *thd __attribute__((unused)),
3566
 
                             char *path, enum legacy_db_type *dbt)
 
3571
bool mysql_frm_type(THD *thd __attribute__((unused)),
 
3572
                    char *path, enum legacy_db_type *dbt)
3567
3573
{
3568
3574
  File file;
3569
3575
  uchar header[10];     /* This should be optimized */
3572
3578
  *dbt= DB_TYPE_UNKNOWN;
3573
3579
 
3574
3580
  if ((file= my_open(path, O_RDONLY | O_SHARE, MYF(0))) < 0)
3575
 
    return(FRMTYPE_ERROR);
 
3581
    return false;
3576
3582
  error= my_read(file, (uchar*) header, sizeof(header), MYF(MY_NABP));
3577
3583
  my_close(file, MYF(MY_WME));
3578
3584
 
3579
3585
  if (error)
3580
 
    return(FRMTYPE_ERROR);
 
3586
    return false;
3581
3587
 
3582
3588
  /*  
3583
3589
    This is just a check for DB_TYPE. We'll return default unknown type
3587
3593
  if (header[0] != (uchar) 254 || header[1] != 1 ||
3588
3594
      (header[2] != FRM_VER && header[2] != FRM_VER+1 &&
3589
3595
       (header[2] < FRM_VER+3 || header[2] > FRM_VER+4)))
3590
 
    return(FRMTYPE_TABLE);
 
3596
    return true;
3591
3597
 
3592
3598
  *dbt= (enum legacy_db_type) (uint) *(header + 3);
3593
 
  return(FRMTYPE_TABLE);                   // Is probably a .frm table
 
3599
  return true;                   // Is probably a .frm table
3594
3600
}
3595
3601
 
3596
3602
/****************************************************************************
3599
3605
 
3600
3606
 
3601
3607
/* Prototypes */
3602
 
void free_tmp_table(THD *thd, TABLE *entry);
 
3608
void free_tmp_table(THD *thd, Table *entry);
3603
3609
 
3604
3610
/**
3605
3611
  Create field for temporary table from given field.
3624
3630
*/
3625
3631
 
3626
3632
Field *create_tmp_field_from_field(THD *thd, Field *org_field,
3627
 
                                   const char *name, TABLE *table,
 
3633
                                   const char *name, Table *table,
3628
3634
                                   Item_field *item, uint convert_blob_length)
3629
3635
{
3630
3636
  Field *new_field;
3686
3692
*/
3687
3693
 
3688
3694
static Field *create_tmp_field_from_item(THD *thd __attribute__((unused)),
3689
 
                                         Item *item, TABLE *table,
 
3695
                                         Item *item, Table *table,
3690
3696
                                         Item ***copy_func, bool modify_item,
3691
3697
                                         uint convert_blob_length)
3692
3698
{
3810
3816
*/
3811
3817
 
3812
3818
Field *create_tmp_field_for_schema(THD *thd __attribute__((unused)),
3813
 
                                   Item *item, TABLE *table)
 
3819
                                   Item *item, Table *table)
3814
3820
{
3815
3821
  if (item->field_type() == DRIZZLE_TYPE_VARCHAR)
3816
3822
  {
3859
3865
    new_created field
3860
3866
*/
3861
3867
 
3862
 
Field *create_tmp_field(THD *thd, TABLE *table,Item *item, Item::Type type,
 
3868
Field *create_tmp_field(THD *thd, Table *table,Item *item, Item::Type type,
3863
3869
                        Item ***copy_func, Field **from_field,
3864
3870
                        Field **default_field,
3865
3871
                        bool group, bool modify_item,
3985
3991
#define RATIO_TO_PACK_ROWS             2
3986
3992
#define MIN_STRING_LENGTH_TO_PACK_ROWS   10
3987
3993
 
3988
 
TABLE *
 
3994
Table *
3989
3995
create_tmp_table(THD *thd,TMP_TABLE_PARAM *param,List<Item> &fields,
3990
3996
                 ORDER *group, bool distinct, bool save_sum_fields,
3991
3997
                 uint64_t select_options, ha_rows rows_limit,
3992
3998
                 char *table_alias)
3993
3999
{
3994
4000
  MEM_ROOT *mem_root_save, own_root;
3995
 
  TABLE *table;
 
4001
  Table *table;
3996
4002
  TABLE_SHARE *share;
3997
4003
  uint  i,field_count,null_count,null_pack_length;
3998
4004
  uint  copy_func_count= param->func_count;
4662
4668
/****************************************************************************/
4663
4669
 
4664
4670
/**
4665
 
  Create a reduced TABLE object with properly set up Field list from a
 
4671
  Create a reduced Table object with properly set up Field list from a
4666
4672
  list of field definitions.
4667
4673
 
4668
4674
    The created table doesn't have a table handler associated with
4669
4675
    it, has no keys, no group/distinct, no copy_funcs array.
4670
 
    The sole purpose of this TABLE object is to use the power of Field
 
4676
    The sole purpose of this Table object is to use the power of Field
4671
4677
    class to read/write data to/from table->record[0]. Then one can store
4672
4678
    the record in any container (RB tree, hash, etc).
4673
4679
    The table is created in THD mem_root, so are the table's fields.
4677
4683
  @param field_list  list of column definitions
4678
4684
 
4679
4685
  @return
4680
 
    0 if out of memory, TABLE object in case of success
 
4686
    0 if out of memory, Table object in case of success
4681
4687
*/
4682
4688
 
4683
 
TABLE *create_virtual_tmp_table(THD *thd, List<Create_field> &field_list)
 
4689
Table *create_virtual_tmp_table(THD *thd, List<Create_field> &field_list)
4684
4690
{
4685
4691
  uint field_count= field_list.elements;
4686
4692
  uint blob_count= 0;
4691
4697
  uint null_pack_length;              /* NULL representation array length */
4692
4698
  uint *blob_field;
4693
4699
  uchar *bitmaps;
4694
 
  TABLE *table;
 
4700
  Table *table;
4695
4701
  TABLE_SHARE *share;
4696
4702
 
4697
4703
  if (!multi_alloc_root(thd->mem_root,
4976
4982
  to this.
4977
4983
*/
4978
4984
 
4979
 
bool create_myisam_from_heap(THD *thd, TABLE *table,
 
4985
bool create_myisam_from_heap(THD *thd, Table *table,
4980
4986
                             MI_COLUMNDEF *start_recinfo,
4981
4987
                             MI_COLUMNDEF **recinfo, 
4982
4988
                             int error, bool ignore_last_dupp_key_error)
4983
4989
{
4984
 
  TABLE new_table;
 
4990
  Table new_table;
4985
4991
  TABLE_SHARE share;
4986
4992
  const char *save_proc_info;
4987
4993
  int write_err;