~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/table.cc

  • Committer: Brian Aker
  • Date: 2011-02-22 06:12:02 UTC
  • mfrom: (2190.1.6 drizzle-build)
  • Revision ID: brian@tangent.org-20110222061202-k03czxykqy4x9hjs
List update, header fixes, multiple symbols, and David deletes some code.

Show diffs side-by-side

added added

removed removed

Lines of Context:
16
16
 
17
17
/* Some general useful functions */
18
18
 
19
 
#include "config.h"
 
19
#include <config.h>
20
20
 
21
21
#include <float.h>
22
22
#include <fcntl.h>
28
28
#include <drizzled/error.h>
29
29
#include <drizzled/gettext.h>
30
30
 
31
 
#include "drizzled/plugin/transactional_storage_engine.h"
32
 
#include "drizzled/plugin/authorization.h"
 
31
#include <drizzled/plugin/transactional_storage_engine.h>
 
32
#include <drizzled/plugin/authorization.h>
33
33
#include <drizzled/nested_join.h>
34
34
#include <drizzled/sql_parse.h>
35
35
#include <drizzled/item/sum.h>
42
42
#include <drizzled/field/double.h>
43
43
#include <drizzled/unireg.h>
44
44
#include <drizzled/message/table.pb.h>
45
 
#include "drizzled/sql_table.h"
46
 
#include "drizzled/charset.h"
47
 
#include "drizzled/internal/m_string.h"
48
 
#include "plugin/myisam/myisam.h"
 
45
#include <drizzled/sql_table.h>
 
46
#include <drizzled/charset.h>
 
47
#include <drizzled/internal/m_string.h>
 
48
#include <plugin/myisam/myisam.h>
 
49
#include <drizzled/plugin/storage_engine.h>
49
50
 
50
51
#include <drizzled/item/string.h>
51
52
#include <drizzled/item/int.h>
54
55
#include <drizzled/item/null.h>
55
56
#include <drizzled/temporal.h>
56
57
 
57
 
#include "drizzled/table/instance.h"
58
 
 
59
 
#include "drizzled/table_proto.h"
 
58
#include <drizzled/refresh_version.h>
 
59
 
 
60
#include <drizzled/table/singular.h>
 
61
 
 
62
#include <drizzled/table_proto.h>
 
63
#include <drizzled/typelib.h>
60
64
 
61
65
using namespace std;
62
66
 
63
67
namespace drizzled
64
68
{
65
69
 
66
 
extern pid_t current_pid;
67
70
extern plugin::StorageEngine *heap_engine;
68
71
extern plugin::StorageEngine *myisam_engine;
69
72
 
70
73
/* Functions defined in this cursor */
71
74
 
72
 
void open_table_error(TableShare *share, int error, int db_errno,
73
 
                      myf errortype, int errarg);
74
 
 
75
75
/*************************************************************************/
76
76
 
77
77
// @note this should all be the destructor
82
82
  if (db_stat)
83
83
    error= cursor->close();
84
84
  _alias.clear();
 
85
 
85
86
  if (field)
86
87
  {
87
88
    for (Field **ptr=field ; *ptr ; ptr++)
90
91
    }
91
92
    field= 0;
92
93
  }
93
 
  delete cursor;
94
 
  cursor= 0;                            /* For easier errorchecking */
 
94
  safe_delete(cursor);
95
95
 
96
96
  if (free_share)
97
97
  {
112
112
                       uint32_t db_stat_arg)
113
113
{
114
114
  setShare(share);
 
115
  in_use= session;
 
116
 
115
117
  field= NULL;
116
118
 
117
119
  cursor= NULL;
124
126
  tablenr= 0;
125
127
  db_stat= db_stat_arg;
126
128
 
127
 
  in_use= session;
128
129
  record[0]= (unsigned char *) NULL;
129
130
  record[1]= (unsigned char *) NULL;
130
131
 
196
197
 
197
198
/* Deallocate temporary blob storage */
198
199
 
199
 
void free_blobs(register Table *table)
 
200
void free_blobs(Table *table)
200
201
{
201
202
  uint32_t *ptr, *end;
202
203
  for (ptr= table->getBlobField(), end=ptr + table->sizeBlobFields();
222
223
    
223
224
  result->type_lengths= (uint*) (result->type_names + result->count + 1);
224
225
 
225
 
  List_iterator<String> it(strings);
 
226
  List<String>::iterator it(strings.begin());
226
227
  String *tmp;
227
228
  for (uint32_t i= 0; (tmp= it++); i++)
228
229
  {
238
239
 
239
240
        /* Check that the integer is in the internal */
240
241
 
241
 
int set_zone(register int nr, int min_zone, int max_zone)
 
242
int set_zone(int nr, int min_zone, int max_zone)
242
243
{
243
244
  if (nr<=min_zone)
244
245
    return (min_zone);
322
323
}
323
324
 
324
325
/*
325
 
  Check if database name is valid
326
 
 
327
 
  SYNPOSIS
328
 
    check_db_name()
329
 
    org_name            Name of database and length
330
 
 
331
 
  RETURN
332
 
    false error
333
 
    true ok
334
 
*/
335
 
 
336
 
bool check_db_name(Session *session, SchemaIdentifier &schema_identifier)
337
 
{
338
 
  if (not plugin::Authorization::isAuthorized(session->getSecurityContext(), schema_identifier))
339
 
  {
340
 
    return false;
341
 
  }
342
 
 
343
 
  return schema_identifier.isValid();
344
 
}
345
 
 
346
 
/*
347
326
  Allow anything as a table name, as long as it doesn't contain an
348
327
  ' ' at the end
349
328
  returns 1 on error
521
500
    We must set bit in read set as update_auto_increment() is using the
522
501
    store() to check overflow of auto_increment values
523
502
  */
524
 
  setReadSet(found_next_number_field->field_index);
525
 
  setWriteSet(found_next_number_field->field_index);
 
503
  setReadSet(found_next_number_field->position());
 
504
  setWriteSet(found_next_number_field->position());
526
505
  if (getShare()->next_number_keypart)
527
506
    mark_columns_used_by_index_no_reset(getShare()->next_number_index);
528
507
}
571
550
    for (reg_field= field ; *reg_field ; reg_field++)
572
551
    {
573
552
      if ((*reg_field)->flags & PART_KEY_FLAG)
574
 
        setReadSet((*reg_field)->field_index);
 
553
        setReadSet((*reg_field)->position());
575
554
    }
576
555
  }
577
556
}
620
599
    {
621
600
      /* Merge keys is all keys that had a column refered to in the query */
622
601
      if (is_overlapping(merge_keys, (*reg_field)->part_of_key))
623
 
        setReadSet((*reg_field)->field_index);
 
602
        setReadSet((*reg_field)->position());
624
603
    }
625
604
  }
626
605
 
661
640
void Table::setVariableWidth(void)
662
641
{
663
642
  assert(in_use);
664
 
  if (in_use && in_use->lex->sql_command == SQLCOM_CREATE_TABLE)
 
643
  if (in_use && in_use->getLex()->sql_command == SQLCOM_CREATE_TABLE)
665
644
  {
666
645
    getMutableShare()->setVariableWidth();
667
646
    return;
838
817
    copy_func_count+= param->sum_func_count;
839
818
  }
840
819
 
841
 
  table::Instance *table;
 
820
  table::Singular *table;
842
821
  table= session->getInstanceTable(); // This will not go into the tableshare cache, so no key is used.
843
822
 
844
823
  if (not table->getMemRoot()->multi_alloc_root(0,
884
863
 
885
864
  table->getMutableShare()->blob_field.resize(field_count+1);
886
865
  uint32_t *blob_field= &table->getMutableShare()->blob_field[0];
887
 
  table->getMutableShare()->blob_ptr_size= portable_sizeof_char_ptr;
888
866
  table->getMutableShare()->db_low_byte_first=1;                // True for HEAP and MyISAM
889
867
  table->getMutableShare()->table_charset= param->table_charset;
890
868
  table->getMutableShare()->keys_for_keyread.reset();
896
874
  blob_count= string_count= null_count= hidden_null_count= group_null_items= 0;
897
875
  param->using_indirect_summary_function= 0;
898
876
 
899
 
  List_iterator_fast<Item> li(fields);
 
877
  List<Item>::iterator li(fields.begin());
900
878
  Item *item;
901
879
  Field **tmp_from_field=from_field;
902
880
  while ((item=li++))
965
943
            */
966
944
            (*argp)->maybe_null=1;
967
945
          }
968
 
          new_field->field_index= fieldnr++;
 
946
          new_field->setPosition(fieldnr++);
969
947
        }
970
948
      }
971
949
    }
1012
990
        group_null_items++;
1013
991
        new_field->flags|= GROUP_FLAG;
1014
992
      }
1015
 
      new_field->field_index= fieldnr++;
 
993
      new_field->setPosition(fieldnr++);
1016
994
      *(reg_field++)= new_field;
1017
995
    }
1018
996
    if (!--hidden_field_count)
1035
1013
  field_count= fieldnr;
1036
1014
  *reg_field= 0;
1037
1015
  *blob_field= 0;                               // End marker
1038
 
  table->getMutableShare()->fields= field_count;
 
1016
  table->getMutableShare()->setFieldSize(field_count);
1039
1017
 
1040
1018
  /* If result table is small; use a heap */
1041
1019
  /* future: storage engine selection can be made dynamic? */
1042
1020
  if (blob_count || using_unique_constraint || 
1043
 
      (session->lex->select_lex.options & SELECT_BIG_RESULT) ||
1044
 
      (session->lex->current_select->olap == ROLLUP_TYPE) ||
 
1021
      (session->getLex()->select_lex.options & SELECT_BIG_RESULT) ||
 
1022
      (session->getLex()->current_select->olap == ROLLUP_TYPE) ||
1045
1023
      (select_options & (OPTION_BIG_TABLES | SELECT_SMALL_RESULT)) == OPTION_BIG_TABLES)
1046
1024
  {
1047
1025
    table->getMutableShare()->storage_engine= myisam_engine;
1507
1485
    for (Field **ptr= this->field ; *ptr != NULL; ptr++)
1508
1486
    {
1509
1487
      Field *f= *ptr;
1510
 
      if (write_set->test(f->field_index))
 
1488
      if (write_set->test(f->position()))
1511
1489
      {
1512
1490
        if (f->real_maybe_null())
1513
1491
        {
1540
1518
  /* Compare updated fields */
1541
1519
  for (Field **ptr= field ; *ptr ; ptr++)
1542
1520
  {
1543
 
    if (isWriteSet((*ptr)->field_index) &&
 
1521
    if (isWriteSet((*ptr)->position()) &&
1544
1522
        (*ptr)->cmp_binary_offset(getShare()->rec_buff_length))
1545
1523
      return true;
1546
1524
  }
1647
1625
  query_id(0),
1648
1626
  quick_condition_rows(0),
1649
1627
  timestamp_field_type(TIMESTAMP_NO_AUTO_SET),
1650
 
  map(0)
 
1628
  map(0),
 
1629
  quick_rows(),
 
1630
  const_key_parts(),
 
1631
  quick_key_parts(),
 
1632
  quick_n_ranges()
1651
1633
{
1652
1634
  record[0]= (unsigned char *) 0;
1653
1635
  record[1]= (unsigned char *) 0;
1654
 
 
1655
 
  reginfo.reset();
1656
 
  covering_keys.reset();
1657
 
  quick_keys.reset();
1658
 
  merge_keys.reset();
1659
 
 
1660
 
  keys_in_use_for_query.reset();
1661
 
  keys_in_use_for_group_by.reset();
1662
 
  keys_in_use_for_order_by.reset();
1663
 
 
1664
 
  memset(quick_rows, 0, sizeof(ha_rows) * MAX_KEY);
1665
 
  memset(const_key_parts, 0, sizeof(ha_rows) * MAX_KEY);
1666
 
 
1667
 
  memset(quick_key_parts, 0, sizeof(unsigned int) * MAX_KEY);
1668
 
  memset(quick_n_ranges, 0, sizeof(unsigned int) * MAX_KEY);
1669
1636
}
1670
1637
 
1671
1638
/*****************************************************************************
1687
1654
    print them to the .err log
1688
1655
  */
1689
1656
  if (error != HA_ERR_LOCK_DEADLOCK && error != HA_ERR_LOCK_WAIT_TIMEOUT)
1690
 
    errmsg_printf(ERRMSG_LVL_ERROR, _("Got error %d when reading table '%s'"),
 
1657
    errmsg_printf(error::ERROR, _("Got error %d when reading table '%s'"),
1691
1658
                  error, getShare()->getPath());
1692
1659
  print_error(error, MYF(0));
1693
1660
 
1765
1732
  }
1766
1733
}
1767
1734
 
 
1735
/*
 
1736
  Is this instance of the table should be reopen or represents a name-lock?
 
1737
*/
 
1738
bool Table::needs_reopen_or_name_lock() const
 
1739
 
1740
  return getShare()->getVersion() != refresh_version;
 
1741
}
 
1742
 
 
1743
uint32_t Table::index_flags(uint32_t idx) const
 
1744
{
 
1745
  return getShare()->getEngine()->index_flags(getShare()->getKeyInfo(idx).algorithm);
 
1746
}
 
1747
 
 
1748
void Table::print_error(int error, myf errflag) const
 
1749
{
 
1750
  getShare()->getEngine()->print_error(error, errflag, *this);
 
1751
}
 
1752
 
1768
1753
} /* namespace drizzled */