~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/table.cc

  • Committer: Andrew Hutchings
  • Date: 2011-01-04 20:16:55 UTC
  • mto: This revision was merged to the branch mainline in revision 2057.
  • Revision ID: andrew@linuxjedi.co.uk-20110104201655-fm6splh5wqpv8wnb
Revert join_cache buffer cleanup, causes valgrind problems and as much as I don't like it I think the current implementation seems to work

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>
49
 
#include <drizzled/plugin/storage_engine.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"
50
49
 
51
50
#include <drizzled/item/string.h>
52
51
#include <drizzled/item/int.h>
55
54
#include <drizzled/item/null.h>
56
55
#include <drizzled/temporal.h>
57
56
 
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>
 
57
#include "drizzled/table/instance.h"
 
58
 
 
59
#include "drizzled/table_proto.h"
64
60
 
65
61
using namespace std;
66
62
 
67
63
namespace drizzled
68
64
{
69
65
 
 
66
extern pid_t current_pid;
70
67
extern plugin::StorageEngine *heap_engine;
71
68
extern plugin::StorageEngine *myisam_engine;
72
69
 
73
70
/* Functions defined in this cursor */
74
71
 
 
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
 
 
86
85
  if (field)
87
86
  {
88
87
    for (Field **ptr=field ; *ptr ; ptr++)
91
90
    }
92
91
    field= 0;
93
92
  }
94
 
  safe_delete(cursor);
 
93
  delete cursor;
 
94
  cursor= 0;                            /* For easier errorchecking */
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
 
 
117
115
  field= NULL;
118
116
 
119
117
  cursor= NULL;
126
124
  tablenr= 0;
127
125
  db_stat= db_stat_arg;
128
126
 
 
127
  in_use= session;
129
128
  record[0]= (unsigned char *) NULL;
130
129
  record[1]= (unsigned char *) NULL;
131
130
 
197
196
 
198
197
/* Deallocate temporary blob storage */
199
198
 
200
 
void free_blobs(Table *table)
 
199
void free_blobs(register Table *table)
201
200
{
202
201
  uint32_t *ptr, *end;
203
202
  for (ptr= table->getBlobField(), end=ptr + table->sizeBlobFields();
223
222
    
224
223
  result->type_lengths= (uint*) (result->type_names + result->count + 1);
225
224
 
226
 
  List<String>::iterator it(strings.begin());
 
225
  List_iterator<String> it(strings);
227
226
  String *tmp;
228
227
  for (uint32_t i= 0; (tmp= it++); i++)
229
228
  {
239
238
 
240
239
        /* Check that the integer is in the internal */
241
240
 
242
 
int set_zone(int nr, int min_zone, int max_zone)
 
241
int set_zone(register int nr, int min_zone, int max_zone)
243
242
{
244
243
  if (nr<=min_zone)
245
244
    return (min_zone);
323
322
}
324
323
 
325
324
/*
 
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->user(), schema_identifier))
 
339
  {
 
340
    return false;
 
341
  }
 
342
 
 
343
  return schema_identifier.isValid();
 
344
}
 
345
 
 
346
/*
326
347
  Allow anything as a table name, as long as it doesn't contain an
327
348
  ' ' at the end
328
349
  returns 1 on error
640
661
void Table::setVariableWidth(void)
641
662
{
642
663
  assert(in_use);
643
 
  if (in_use && in_use->getLex()->sql_command == SQLCOM_CREATE_TABLE)
 
664
  if (in_use && in_use->lex->sql_command == SQLCOM_CREATE_TABLE)
644
665
  {
645
666
    getMutableShare()->setVariableWidth();
646
667
    return;
817
838
    copy_func_count+= param->sum_func_count;
818
839
  }
819
840
 
820
 
  table::Singular *table;
 
841
  table::Instance *table;
821
842
  table= session->getInstanceTable(); // This will not go into the tableshare cache, so no key is used.
822
843
 
823
844
  if (not table->getMemRoot()->multi_alloc_root(0,
863
884
 
864
885
  table->getMutableShare()->blob_field.resize(field_count+1);
865
886
  uint32_t *blob_field= &table->getMutableShare()->blob_field[0];
 
887
  table->getMutableShare()->blob_ptr_size= portable_sizeof_char_ptr;
866
888
  table->getMutableShare()->db_low_byte_first=1;                // True for HEAP and MyISAM
867
889
  table->getMutableShare()->table_charset= param->table_charset;
868
890
  table->getMutableShare()->keys_for_keyread.reset();
874
896
  blob_count= string_count= null_count= hidden_null_count= group_null_items= 0;
875
897
  param->using_indirect_summary_function= 0;
876
898
 
877
 
  List<Item>::iterator li(fields.begin());
 
899
  List_iterator_fast<Item> li(fields);
878
900
  Item *item;
879
901
  Field **tmp_from_field=from_field;
880
902
  while ((item=li++))
1018
1040
  /* If result table is small; use a heap */
1019
1041
  /* future: storage engine selection can be made dynamic? */
1020
1042
  if (blob_count || using_unique_constraint || 
1021
 
      (session->getLex()->select_lex.options & SELECT_BIG_RESULT) ||
1022
 
      (session->getLex()->current_select->olap == ROLLUP_TYPE) ||
 
1043
      (session->lex->select_lex.options & SELECT_BIG_RESULT) ||
 
1044
      (session->lex->current_select->olap == ROLLUP_TYPE) ||
1023
1045
      (select_options & (OPTION_BIG_TABLES | SELECT_SMALL_RESULT)) == OPTION_BIG_TABLES)
1024
1046
  {
1025
1047
    table->getMutableShare()->storage_engine= myisam_engine;
1625
1647
  query_id(0),
1626
1648
  quick_condition_rows(0),
1627
1649
  timestamp_field_type(TIMESTAMP_NO_AUTO_SET),
1628
 
  map(0),
1629
 
  quick_rows(),
1630
 
  const_key_parts(),
1631
 
  quick_key_parts(),
1632
 
  quick_n_ranges()
 
1650
  map(0)
1633
1651
{
1634
1652
  record[0]= (unsigned char *) 0;
1635
1653
  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);
1636
1669
}
1637
1670
 
1638
1671
/*****************************************************************************
1654
1687
    print them to the .err log
1655
1688
  */
1656
1689
  if (error != HA_ERR_LOCK_DEADLOCK && error != HA_ERR_LOCK_WAIT_TIMEOUT)
1657
 
    errmsg_printf(error::ERROR, _("Got error %d when reading table '%s'"),
 
1690
    errmsg_printf(ERRMSG_LVL_ERROR, _("Got error %d when reading table '%s'"),
1658
1691
                  error, getShare()->getPath());
1659
1692
  print_error(error, MYF(0));
1660
1693
 
1732
1765
  }
1733
1766
}
1734
1767
 
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
 
 
1753
1768
} /* namespace drizzled */