17
17
/* Some general useful functions */
19
#include <drizzled/server_includes.h>
20
28
#include <drizzled/error.h>
21
29
#include <drizzled/gettext.h>
31
#include "drizzled/plugin/info_schema_table.h"
23
32
#include <drizzled/nested_join.h>
24
33
#include <drizzled/sql_parse.h>
25
34
#include <drizzled/item/sum.h>
32
41
#include <drizzled/field/double.h>
33
42
#include <drizzled/unireg.h>
34
43
#include <drizzled/message/table.pb.h>
44
#include "drizzled/sql_table.h"
45
#include "drizzled/charset.h"
46
#include "drizzled/internal/m_string.h"
47
#include "plugin/myisam/myisam.h"
36
49
#include <drizzled/item/string.h>
37
50
#include <drizzled/item/int.h>
43
56
#include "drizzled/table_proto.h"
49
using namespace drizzled;
50
58
using namespace std;
51
59
using namespace drizzled;
61
extern pid_t current_pid;
62
extern plugin::StorageEngine *heap_engine;
63
extern plugin::StorageEngine *myisam_engine;
53
65
/* Functions defined in this cursor */
55
67
void open_table_error(TableShare *share, int error, int db_errno,
107
119
path_length= build_table_filename(path, sizeof(path) - 1,
109
121
table_list->table_name, false);
110
init_sql_alloc(&mem_root, TABLE_ALLOC_BLOCK_SIZE, 0);
122
memory::init_sql_alloc(&mem_root, TABLE_ALLOC_BLOCK_SIZE, 0);
111
123
if (multi_alloc_root(&mem_root,
112
124
&share, sizeof(*share),
113
125
&key_buff, key_length,
390
399
case message::Table::Index::BTREE:
391
400
keyinfo->algorithm= HA_KEY_ALG_BTREE;
393
case message::Table::Index::RTREE:
394
keyinfo->algorithm= HA_KEY_ALG_RTREE;
396
402
case message::Table::Index::HASH:
397
403
keyinfo->algorithm= HA_KEY_ALG_HASH;
399
case message::Table::Index::FULLTEXT:
400
keyinfo->algorithm= HA_KEY_ALG_FULLTEXT;
403
407
/* TODO: suitable warning ? */
818
822
memset(&temp_table, 0, sizeof(temp_table));
819
823
temp_table.s= share;
820
824
temp_table.in_use= &session;
821
temp_table.s->db_low_byte_first= 1; //Cursor->low_byte_first();
825
temp_table.s->db_low_byte_first= true; //Cursor->low_byte_first();
822
826
temp_table.s->blob_ptr_size= portable_sizeof_char_ptr;
824
828
uint32_t field_length= 0; //Assignment is for compiler complaint.
1090
1091
if (field->key_length() == key_part->length &&
1091
1092
!(field->flags & BLOB_FLAG))
1093
if (handler_file->index_flags(key, i, 0) & HA_KEYREAD_ONLY)
1094
enum ha_key_alg algo= share->key_info[key].algorithm;
1095
if (share->db_type()->index_flags(algo) & HA_KEYREAD_ONLY)
1095
1097
share->keys_for_keyread.set(key);
1096
1098
field->part_of_key.set(key);
1097
1099
field->part_of_key_not_clustered.set(key);
1099
if (handler_file->index_flags(key, i, 1) & HA_READ_ORDER)
1101
if (share->db_type()->index_flags(algo) & HA_READ_ORDER)
1100
1102
field->part_of_sortkey.set(key);
1102
1104
if (!(key_part->key_part_flag & HA_REVERSE_SORT) &&
1127
1129
set_if_bigger(share->max_key_length,keyinfo->key_length+
1128
1130
keyinfo->key_parts);
1129
1131
share->total_key_length+= keyinfo->key_length;
1131
MERGE tables do not have unique indexes. But every key could be
1132
an unique index on the underlying MyISAM table. (Bug #10400)
1134
if ((keyinfo->flags & HA_NOSAME) ||
1135
(handler_file->getEngine()->check_flag(HTON_BIT_ANY_INDEX_MAY_BE_UNIQUE)))
1133
if (keyinfo->flags & HA_NOSAME)
1136
1135
set_if_bigger(share->max_unique_length,keyinfo->key_length);
1138
1138
if (primary_key < MAX_KEY &&
1139
1139
(share->keys_in_use.test(primary_key)))
1216
1214
free(field_pack_length);
1218
1216
share->error= error;
1219
share->open_errno= my_errno;
1217
share->open_errno= errno;
1220
1218
share->errarg= 0;
1221
1219
hash_free(&share->name_hash);
1223
delete handler_file;
1224
1220
share->open_table_error(error, share->open_errno, 0);
1294
1290
if (error && !error_given)
1296
1292
share->error= error;
1297
share->open_table_error(error, (share->open_errno= my_errno), 0);
1293
share->open_table_error(error, (share->open_errno= errno), 0);
1329
1324
int open_table_from_share(Session *session, TableShare *share, const char *alias,
1330
uint32_t db_stat, uint32_t prgflag, uint32_t ha_open_flags,
1325
uint32_t db_stat, uint32_t ha_open_flags,
1331
1326
Table *outparam)
1349
1344
/* Allocate Cursor */
1350
if (!(prgflag & OPEN_FRM_FILE_ONLY))
1352
if (!(outparam->cursor= share->db_type()->getCursor(*share, &outparam->mem_root)))
1345
if (!(outparam->cursor= share->db_type()->getCursor(*share, &outparam->mem_root)))
1362
if ((db_stat & HA_OPEN_KEYFILE) || (prgflag & DELAYED_OPEN))
1350
if ((db_stat & HA_OPEN_KEYFILE))
1364
if (prgflag & (READ_ALL+EXTRA_RECORD))
1367
1355
if (!(record= (unsigned char*) alloc_root(&outparam->mem_root,
1368
1356
share->rec_buff_length * records)))
1534
if (!error_reported && !(prgflag & DONT_GIVE_ERROR))
1535
share->open_table_error(error, my_errno, 0);
1522
if (!error_reported)
1523
share->open_table_error(error, errno, 0);
1536
1524
delete outparam->cursor;
1537
1525
outparam->cursor= 0; // For easier error checking
1538
1526
outparam->db_stat= 0;
1576
void Table::resetTable(Session *session,
1578
uint32_t db_stat_arg)
1591
db_stat= db_stat_arg;
1594
record[0]= (unsigned char *) NULL;
1595
record[1]= (unsigned char *) NULL;
1597
insert_values= NULL;
1599
next_number_field= NULL;
1600
found_next_number_field= NULL;
1601
timestamp_field= NULL;
1603
pos_in_table_list= NULL;
1613
derived_select_number= 0;
1614
current_lock= F_UNLCK;
1628
open_placeholder= false;
1629
locked_by_name= false;
1632
auto_increment_field_not_null= false;
1633
alias_name_used= false;
1636
quick_condition_rows= 0;
1638
timestamp_field_type= TIMESTAMP_NO_AUTO_SET;
1643
covering_keys.reset();
1648
keys_in_use_for_query.reset();
1649
keys_in_use_for_group_by.reset();
1650
keys_in_use_for_order_by.reset();
1652
memset(quick_rows, 0, sizeof(ha_rows) * MAX_KEY);
1653
memset(const_key_parts, 0, sizeof(ha_rows) * MAX_KEY);
1655
memset(quick_key_parts, 0, sizeof(unsigned int) * MAX_KEY);
1656
memset(quick_n_ranges, 0, sizeof(unsigned int) * MAX_KEY);
1658
memory::init_sql_alloc(&mem_root, TABLE_ALLOC_BLOCK_SIZE, 0);
1659
memset(&sort, 0, sizeof(filesort_info_st));
1588
1664
/* Deallocate temporary blob storage */
1590
1666
void free_blobs(register Table *table)
1670
1746
} /* open_table_error */
1673
TYPELIB *typelib(MEM_ROOT *mem_root, List<String> &strings)
1749
TYPELIB *typelib(memory::Root *mem_root, List<String> &strings)
1675
1751
TYPELIB *result= (TYPELIB*) alloc_root(mem_root, sizeof(TYPELIB));
2293
2368
uint64_t select_options, ha_rows rows_limit,
2294
2369
const char *table_alias)
2296
MEM_ROOT *mem_root_save, own_root;
2371
memory::Root *mem_root_save, own_root;
2298
2373
TableShare *share;
2299
2374
uint i,field_count,null_count,null_pack_length;
2367
2442
if (param->precomputed_group_by)
2368
2443
copy_func_count+= param->sum_func_count;
2370
init_sql_alloc(&own_root, TABLE_ALLOC_BLOCK_SIZE, 0);
2445
memory::init_sql_alloc(&own_root, TABLE_ALLOC_BLOCK_SIZE, 0);
2372
2447
if (!multi_alloc_root(&own_root,
2373
2448
&table, sizeof(*table),
2900
2975
key_part_info->length= (uint16_t) (*reg_field)->pack_length();
2902
2977
The below method of computing the key format length of the
2903
key part is a copy/paste from opt_range.cc, and table.cc.
2978
key part is a copy/paste from optimizer/range.cc, and table.cc.
2904
2979
This should be factored out, e.g. as a method of Field.
2905
2980
In addition it is not clear if any of the Field::*_length
2906
2981
methods is supposed to compute the same length. If so, it
3233
3308
void Table::free_tmp_table(Session *session)
3235
MEM_ROOT own_root= mem_root;
3310
memory::Root own_root= mem_root;
3236
3311
const char *save_proc_info;
3238
3313
save_proc_info=session->get_proc_info();
3493
3568
memset(null_flags, 255, s->null_bytes);
3582
insert_values(NULL),
3584
next_number_field(NULL),
3585
found_next_number_field(NULL),
3586
timestamp_field(NULL),
3587
pos_in_table_list(NULL),
3596
derived_select_number(0),
3597
current_lock(F_UNLCK),
3607
open_placeholder(false),
3608
locked_by_name(false),
3610
auto_increment_field_not_null(false),
3611
alias_name_used(false),
3613
quick_condition_rows(0),
3614
timestamp_field_type(TIMESTAMP_NO_AUTO_SET),
3617
record[0]= (unsigned char *) 0;
3618
record[1]= (unsigned char *) 0;
3620
covering_keys.reset();
3625
keys_in_use_for_query.reset();
3626
keys_in_use_for_group_by.reset();
3627
keys_in_use_for_order_by.reset();
3629
memset(quick_rows, 0, sizeof(ha_rows) * MAX_KEY);
3630
memset(const_key_parts, 0, sizeof(ha_rows) * MAX_KEY);
3632
memset(quick_key_parts, 0, sizeof(unsigned int) * MAX_KEY);
3633
memset(quick_n_ranges, 0, sizeof(unsigned int) * MAX_KEY);
3635
memory::init_sql_alloc(&mem_root, TABLE_ALLOC_BLOCK_SIZE, 0);
3636
memset(&sort, 0, sizeof(filesort_info_st));
3496
3639
/*****************************************************************************
3497
3640
The different ways to read a record
3498
3641
Returns -1 if row was not found, 0 if row was found and 1 on errors