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>
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"
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>
58
#include <drizzled/refresh_version.h>
60
#include <drizzled/table/singular.h>
62
#include <drizzled/table_proto.h>
63
#include <drizzled/typelib.h>
57
#include "drizzled/table/instance.h"
59
#include "drizzled/table_proto.h"
65
61
using namespace std;
66
extern pid_t current_pid;
70
67
extern plugin::StorageEngine *heap_engine;
71
68
extern plugin::StorageEngine *myisam_engine;
73
70
/* Functions defined in this cursor */
72
void open_table_error(TableShare *share, int error, int db_errno,
73
myf errortype, int errarg);
75
75
/*************************************************************************/
77
77
// @note this should all be the destructor
198
205
/* Deallocate temporary blob storage */
200
void free_blobs(Table *table)
207
void free_blobs(register Table *table)
202
209
uint32_t *ptr, *end;
203
210
for (ptr= table->getBlobField(), end=ptr + table->sizeBlobFields();
240
247
/* Check that the integer is in the internal */
242
int set_zone(int nr, int min_zone, int max_zone)
249
int set_zone(register int nr, int min_zone, int max_zone)
244
251
if (nr<=min_zone)
245
252
return (min_zone);
258
/* Adjust number to next larger disk buffer */
260
ulong next_io_size(register ulong pos)
262
register ulong offset;
263
if ((offset= pos & (IO_SIZE-1)))
264
return pos-offset+IO_SIZE;
253
270
Store an SQL quoted string.
343
Check if database name is valid
347
org_name Name of database and length
354
bool check_db_name(Session *session, SchemaIdentifier &schema_identifier)
356
if (not plugin::Authorization::isAuthorized(session->getSecurityContext(), schema_identifier))
361
return schema_identifier.isValid();
326
365
Allow anything as a table name, as long as it doesn't contain an
328
367
returns 1 on error
500
539
We must set bit in read set as update_auto_increment() is using the
501
540
store() to check overflow of auto_increment values
503
setReadSet(found_next_number_field->position());
504
setWriteSet(found_next_number_field->position());
542
setReadSet(found_next_number_field->field_index);
543
setWriteSet(found_next_number_field->field_index);
505
544
if (getShare()->next_number_keypart)
506
545
mark_columns_used_by_index_no_reset(getShare()->next_number_index);
600
639
/* Merge keys is all keys that had a column refered to in the query */
601
640
if (is_overlapping(merge_keys, (*reg_field)->part_of_key))
602
setReadSet((*reg_field)->position());
641
setReadSet((*reg_field)->field_index);
752
791
create_tmp_table(Session *session,Tmp_Table_Param *param,List<Item> &fields,
753
Order *group, bool distinct, bool save_sum_fields,
792
order_st *group, bool distinct, bool save_sum_fields,
754
793
uint64_t select_options, ha_rows rows_limit,
755
794
const char *table_alias)
864
903
table->getMutableShare()->blob_field.resize(field_count+1);
865
904
uint32_t *blob_field= &table->getMutableShare()->blob_field[0];
905
table->getMutableShare()->blob_ptr_size= portable_sizeof_char_ptr;
866
906
table->getMutableShare()->db_low_byte_first=1; // True for HEAP and MyISAM
867
907
table->getMutableShare()->table_charset= param->table_charset;
868
908
table->getMutableShare()->keys_for_keyread.reset();
874
914
blob_count= string_count= null_count= hidden_null_count= group_null_items= 0;
875
915
param->using_indirect_summary_function= 0;
877
List<Item>::iterator li(fields.begin());
917
List_iterator_fast<Item> li(fields);
879
919
Field **tmp_from_field=from_field;
880
920
while ((item=li++))
990
1030
group_null_items++;
991
1031
new_field->flags|= GROUP_FLAG;
993
new_field->setPosition(fieldnr++);
1033
new_field->field_index= fieldnr++;
994
1034
*(reg_field++)= new_field;
996
1036
if (!--hidden_field_count)
1013
1053
field_count= fieldnr;
1015
1055
*blob_field= 0; // End marker
1016
table->getMutableShare()->setFieldSize(field_count);
1056
table->getMutableShare()->fields= field_count;
1018
1058
/* If result table is small; use a heap */
1019
1059
/* future: storage engine selection can be made dynamic? */
1020
1060
if (blob_count || using_unique_constraint ||
1021
(session->getLex()->select_lex.options & SELECT_BIG_RESULT) ||
1022
(session->getLex()->current_select->olap == ROLLUP_TYPE) ||
1061
(session->lex->select_lex.options & SELECT_BIG_RESULT) ||
1062
(session->lex->current_select->olap == ROLLUP_TYPE) ||
1023
1063
(select_options & (OPTION_BIG_TABLES | SELECT_SMALL_RESULT)) == OPTION_BIG_TABLES)
1025
1065
table->getMutableShare()->storage_engine= myisam_engine;
1216
1256
keyinfo->rec_per_key= 0;
1217
1257
keyinfo->algorithm= HA_KEY_ALG_UNDEF;
1218
1258
keyinfo->name= (char*) "group_key";
1219
Order *cur_group= group;
1259
order_st *cur_group= group;
1220
1260
for (; cur_group ; cur_group= cur_group->next, key_part_info++)
1222
1262
Field *field=(*cur_group->item)->get_tmp_table_field();
1454
True if the table's input and output record buffers are comparable using
1455
compare_records(TABLE*).
1457
bool Table::records_are_comparable()
1459
return ((getEngine()->check_flag(HTON_BIT_PARTIAL_COLUMN_READ) == 0) ||
1460
write_set->is_subset_of(*read_set));
1464
Compares the input and outbut record buffers of the table to see if a row
1465
has changed. The algorithm iterates over updated columns and if they are
1466
nullable compares NULL bits in the buffer before comparing actual
1467
data. Special care must be taken to compare only the relevant NULL bits and
1468
mask out all others as they may be undefined. The storage engine will not
1469
and should not touch them.
1471
@param table The table to evaluate.
1473
@return true if row has changed.
1474
@return false otherwise.
1476
bool Table::compare_records()
1478
if (getEngine()->check_flag(HTON_BIT_PARTIAL_COLUMN_READ) != 0)
1481
Storage engine may not have read all columns of the record. Fields
1482
(including NULL bits) not in the write_set may not have been read and
1483
can therefore not be compared.
1485
for (Field **ptr= this->field ; *ptr != NULL; ptr++)
1488
if (write_set->test(f->position()))
1490
if (f->real_maybe_null())
1492
unsigned char null_byte_index= f->null_ptr - record[0];
1494
if (((record[0][null_byte_index]) & f->null_bit) !=
1495
((record[1][null_byte_index]) & f->null_bit))
1498
if (f->cmp_binary_offset(getShare()->rec_buff_length))
1506
The storage engine has read all columns, so it's safe to compare all bits
1507
including those not in the write_set. This is cheaper than the
1508
field-by-field comparison done above.
1493
/* Return false if row hasn't changed */
1495
bool Table::compare_record()
1510
1497
if (not getShare()->blob_fields + getShare()->hasVariableWidth())
1511
// Fixed-size record: do bitwise comparison of the records
1512
1498
return memcmp(this->getInsertRecord(), this->getUpdateRecord(), (size_t) getShare()->getRecordLength());
1514
1500
/* Compare null bits */
1515
1501
if (memcmp(null_flags, null_flags + getShare()->rec_buff_length, getShare()->null_bytes))
1516
1502
return true; /* Diff in NULL value */
1518
1504
/* Compare updated fields */
1519
1505
for (Field **ptr= field ; *ptr ; ptr++)
1521
if (isWriteSet((*ptr)->position()) &&
1507
if (isWriteSet((*ptr)->field_index) &&
1522
1508
(*ptr)->cmp_binary_offset(getShare()->rec_buff_length))
1626
1612
quick_condition_rows(0),
1627
1613
timestamp_field_type(TIMESTAMP_NO_AUTO_SET),
1634
1616
record[0]= (unsigned char *) 0;
1635
1617
record[1]= (unsigned char *) 0;
1620
covering_keys.reset();
1624
keys_in_use_for_query.reset();
1625
keys_in_use_for_group_by.reset();
1626
keys_in_use_for_order_by.reset();
1628
memset(quick_rows, 0, sizeof(ha_rows) * MAX_KEY);
1629
memset(const_key_parts, 0, sizeof(ha_rows) * MAX_KEY);
1631
memset(quick_key_parts, 0, sizeof(unsigned int) * MAX_KEY);
1632
memset(quick_n_ranges, 0, sizeof(unsigned int) * MAX_KEY);
1638
1635
/*****************************************************************************
1654
1651
print them to the .err log
1656
1653
if (error != HA_ERR_LOCK_DEADLOCK && error != HA_ERR_LOCK_WAIT_TIMEOUT)
1657
errmsg_printf(error::ERROR, _("Got error %d when reading table '%s'"),
1654
errmsg_printf(ERRMSG_LVL_ERROR, _("Got error %d when reading table '%s'"),
1658
1655
error, getShare()->getPath());
1659
1656
print_error(error, MYF(0));
1702
void Table::filesort_free_buffers(bool full)
1704
if (sort.record_pointers)
1706
free((unsigned char*) sort.record_pointers);
1707
sort.record_pointers=0;
1711
if (sort.sort_keys )
1713
if ((unsigned char*) sort.sort_keys)
1714
free((unsigned char*) sort.sort_keys);
1719
if ((unsigned char*) sort.buffpek)
1720
free((unsigned char*) sort.buffpek);
1722
sort.buffpek_len= 0;
1728
free((char *) sort.addon_buf);
1729
free((char *) sort.addon_field);
1736
Is this instance of the table should be reopen or represents a name-lock?
1738
bool Table::needs_reopen_or_name_lock() const
1740
return getShare()->getVersion() != refresh_version;
1743
uint32_t Table::index_flags(uint32_t idx) const
1745
return getShare()->getEngine()->index_flags(getShare()->getKeyInfo(idx).algorithm);
1748
void Table::print_error(int error, myf errflag) const
1750
getShare()->getEngine()->print_error(error, errflag, *this);
1753
1698
} /* namespace drizzled */