28
28
#include <drizzled/error.h>
29
29
#include <drizzled/gettext.h>
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>
50
50
#include <drizzled/item/string.h>
51
51
#include <drizzled/item/int.h>
52
52
#include <drizzled/item/decimal.h>
53
53
#include <drizzled/item/float.h>
54
54
#include <drizzled/item/null.h>
55
55
#include <drizzled/temporal.h>
57
#include "drizzled/table/instance.h"
59
#include "drizzled/table_proto.h"
56
#include <drizzled/refresh_version.h>
57
#include <drizzled/table/singular.h>
58
#include <drizzled/table_proto.h>
59
#include <drizzled/typelib.h>
60
#include <drizzled/sql_lex.h>
61
#include <drizzled/statistics_variables.h>
62
#include <drizzled/system_variables.h>
61
64
using namespace std;
66
extern pid_t current_pid;
67
68
extern plugin::StorageEngine *heap_engine;
68
69
extern plugin::StorageEngine *myisam_engine;
70
71
/* Functions defined in this cursor */
72
void open_table_error(TableShare *share, int error, int db_errno,
73
myf errortype, int errarg);
75
73
/*************************************************************************/
77
75
// @note this should all be the destructor
197
196
/* Deallocate temporary blob storage */
199
void free_blobs(register Table *table)
198
void free_blobs(Table *table)
201
200
uint32_t *ptr, *end;
202
201
for (ptr= table->getBlobField(), end=ptr + table->sizeBlobFields();
213
212
TYPELIB *result= (TYPELIB*) mem_root->alloc_root(sizeof(TYPELIB));
216
result->count= strings.elements;
215
result->count= strings.size();
217
216
result->name= "";
218
217
uint32_t nbytes= (sizeof(char*) + sizeof(uint32_t)) * (result->count + 1);
239
238
/* Check that the integer is in the internal */
241
int set_zone(register int nr, int min_zone, int max_zone)
240
int set_zone(int nr, int min_zone, int max_zone)
243
242
if (nr<=min_zone)
244
243
return (min_zone);
325
Check if database name is valid
329
org_name Name of database and length
336
bool check_db_name(Session *session, SchemaIdentifier &schema_identifier)
338
if (not plugin::Authorization::isAuthorized(session->user(), schema_identifier))
343
return schema_identifier.isValid();
347
324
Allow anything as a table name, as long as it doesn't contain an
349
326
returns 1 on error
783
760
uint32_t fieldnr= 0;
784
761
ulong reclength, string_total_length;
785
762
bool using_unique_constraint= false;
786
bool use_packed_rows= true;
787
763
bool not_all_columns= !(select_options & TMP_TABLE_ALL_COLUMNS);
788
764
unsigned char *pos, *group_buff;
789
765
unsigned char *null_flags;
838
814
copy_func_count+= param->sum_func_count;
841
table::Instance *table;
842
table= session->getInstanceTable(); // This will not go into the tableshare cache, so no key is used.
817
table::Singular* table= &session->getInstanceTable(); // This will not go into the tableshare cache, so no key is used.
844
819
if (not table->getMemRoot()->multi_alloc_root(0,
845
820
&default_field, sizeof(Field*) * (field_count),
885
860
table->getMutableShare()->blob_field.resize(field_count+1);
886
861
uint32_t *blob_field= &table->getMutableShare()->blob_field[0];
887
table->getMutableShare()->blob_ptr_size= portable_sizeof_char_ptr;
888
862
table->getMutableShare()->db_low_byte_first=1; // True for HEAP and MyISAM
889
863
table->getMutableShare()->table_charset= param->table_charset;
890
864
table->getMutableShare()->keys_for_keyread.reset();
896
870
blob_count= string_count= null_count= hidden_null_count= group_null_items= 0;
897
871
param->using_indirect_summary_function= 0;
899
List_iterator_fast<Item> li(fields);
873
List<Item>::iterator li(fields.begin());
901
875
Field **tmp_from_field=from_field;
902
876
while ((item=li++))
954
928
string_total_length+= new_field->pack_length();
956
930
session->mem_root= mem_root_save;
957
session->change_item_tree(argp, new Item_field(new_field));
931
*argp= new Item_field(new_field);
958
932
session->mem_root= table->getMemRoot();
959
933
if (!(new_field->flags & NOT_NULL_FLAG))
1035
1009
field_count= fieldnr;
1037
1011
*blob_field= 0; // End marker
1038
table->getMutableShare()->fields= field_count;
1012
table->getMutableShare()->setFieldSize(field_count);
1040
1014
/* If result table is small; use a heap */
1041
1015
/* future: storage engine selection can be made dynamic? */
1042
1016
if (blob_count || using_unique_constraint ||
1043
(session->lex->select_lex.options & SELECT_BIG_RESULT) ||
1044
(session->lex->current_select->olap == ROLLUP_TYPE) ||
1017
(session->lex().select_lex.options & SELECT_BIG_RESULT) ||
1018
(session->lex().current_select->olap == ROLLUP_TYPE) ||
1045
1019
(select_options & (OPTION_BIG_TABLES | SELECT_SMALL_RESULT)) == OPTION_BIG_TABLES)
1047
1021
table->getMutableShare()->storage_engine= myisam_engine;
1080
1054
reclength+=null_pack_length;
1081
1055
if (!reclength)
1082
1056
reclength=1; // Dummy select
1083
/* Use packed rows if there is blobs or a lot of space to gain */
1084
if (blob_count || ((string_total_length >= STRING_TOTAL_LENGTH_TO_PACK_ROWS) && (reclength / string_total_length <= RATIO_TO_PACK_ROWS || (string_total_length / string_count) >= AVG_STRING_LENGTH_TO_PACK_ROWS)))
1087
1058
table->getMutableShare()->setRecordLength(reclength);
1648
1619
quick_condition_rows(0),
1649
1620
timestamp_field_type(TIMESTAMP_NO_AUTO_SET),
1652
1627
record[0]= (unsigned char *) 0;
1653
1628
record[1]= (unsigned char *) 0;
1656
covering_keys.reset();
1660
keys_in_use_for_query.reset();
1661
keys_in_use_for_group_by.reset();
1662
keys_in_use_for_order_by.reset();
1664
memset(quick_rows, 0, sizeof(ha_rows) * MAX_KEY);
1665
memset(const_key_parts, 0, sizeof(ha_rows) * MAX_KEY);
1667
memset(quick_key_parts, 0, sizeof(unsigned int) * MAX_KEY);
1668
memset(quick_n_ranges, 0, sizeof(unsigned int) * MAX_KEY);
1671
1631
/*****************************************************************************
1687
1647
print them to the .err log
1689
1649
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'"),
1650
errmsg_printf(error::ERROR, _("Got error %d when reading table '%s'"),
1691
1651
error, getShare()->getPath());
1692
1652
print_error(error, MYF(0));
1719
bool Table::fill_item_list(List<Item> *item_list) const
1679
void Table::fill_item_list(List<Item>& items) const
1722
1682
All Item_field's created using a direct pointer to a field
1723
1683
are fixed in Item_field constructor.
1725
1685
for (Field **ptr= field; *ptr; ptr++)
1727
Item_field *item= new Item_field(*ptr);
1728
if (!item || item_list->push_back(item))
1686
items.push_back(new Item_field(*ptr));
1735
1690
void Table::filesort_free_buffers(bool full)
1737
if (sort.record_pointers)
1739
free((unsigned char*) sort.record_pointers);
1740
sort.record_pointers=0;
1692
free(sort.record_pointers);
1693
sort.record_pointers=0;
1744
if (sort.sort_keys )
1746
if ((unsigned char*) sort.sort_keys)
1747
free((unsigned char*) sort.sort_keys);
1752
if ((unsigned char*) sort.buffpek)
1753
free((unsigned char*) sort.buffpek);
1755
sort.buffpek_len= 0;
1761
free((char *) sort.addon_buf);
1762
free((char *) sort.addon_field);
1696
free(sort.sort_keys);
1700
sort.buffpek_len= 0;
1702
free(sort.addon_buf);
1703
free(sort.addon_field);
1709
Is this instance of the table should be reopen or represents a name-lock?
1711
bool Table::needs_reopen_or_name_lock() const
1713
return getShare()->getVersion() != refresh_version;
1716
uint32_t Table::index_flags(uint32_t idx) const
1718
return getShare()->getEngine()->index_flags(getShare()->getKeyInfo(idx).algorithm);
1721
void Table::print_error(int error, myf errflag) const
1723
getShare()->getEngine()->print_error(error, errflag, *this);
1768
1726
} /* namespace drizzled */