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
197
/* Deallocate temporary blob storage */
200
void free_blobs(Table *table)
199
void free_blobs(register Table *table)
202
201
uint32_t *ptr, *end;
203
202
for (ptr= table->getBlobField(), end=ptr + table->sizeBlobFields();
240
239
/* Check that the integer is in the internal */
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)
244
243
if (nr<=min_zone)
245
244
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->getSecurityContext(), schema_identifier))
343
return schema_identifier.isValid();
326
347
Allow anything as a table name, as long as it doesn't contain an
328
349
returns 1 on error
500
521
We must set bit in read set as update_auto_increment() is using the
501
522
store() to check overflow of auto_increment values
503
setReadSet(found_next_number_field->position());
504
setWriteSet(found_next_number_field->position());
524
setReadSet(found_next_number_field->field_index);
525
setWriteSet(found_next_number_field->field_index);
505
526
if (getShare()->next_number_keypart)
506
527
mark_columns_used_by_index_no_reset(getShare()->next_number_index);
600
621
/* Merge keys is all keys that had a column refered to in the query */
601
622
if (is_overlapping(merge_keys, (*reg_field)->part_of_key))
602
setReadSet((*reg_field)->position());
623
setReadSet((*reg_field)->field_index);
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;
877
List<Item>::iterator li(fields.begin());
899
List_iterator_fast<Item> li(fields);
879
901
Field **tmp_from_field=from_field;
880
902
while ((item=li++))
990
1012
group_null_items++;
991
1013
new_field->flags|= GROUP_FLAG;
993
new_field->setPosition(fieldnr++);
1015
new_field->field_index= fieldnr++;
994
1016
*(reg_field++)= new_field;
996
1018
if (!--hidden_field_count)
1013
1035
field_count= fieldnr;
1015
1037
*blob_field= 0; // End marker
1016
table->getMutableShare()->setFieldSize(field_count);
1038
table->getMutableShare()->fields= field_count;
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)
1025
1047
table->getMutableShare()->storage_engine= myisam_engine;
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.
1475
/* Return false if row hasn't changed */
1477
bool Table::compare_record()
1510
1479
if (not getShare()->blob_fields + getShare()->hasVariableWidth())
1511
// Fixed-size record: do bitwise comparison of the records
1512
1480
return memcmp(this->getInsertRecord(), this->getUpdateRecord(), (size_t) getShare()->getRecordLength());
1514
1482
/* Compare null bits */
1515
1483
if (memcmp(null_flags, null_flags + getShare()->rec_buff_length, getShare()->null_bytes))
1516
1484
return true; /* Diff in NULL value */
1518
1486
/* Compare updated fields */
1519
1487
for (Field **ptr= field ; *ptr ; ptr++)
1521
if (isWriteSet((*ptr)->position()) &&
1489
if (isWriteSet((*ptr)->field_index) &&
1522
1490
(*ptr)->cmp_binary_offset(getShare()->rec_buff_length))
1626
1594
quick_condition_rows(0),
1627
1595
timestamp_field_type(TIMESTAMP_NO_AUTO_SET),
1634
1598
record[0]= (unsigned char *) 0;
1635
1599
record[1]= (unsigned char *) 0;
1602
covering_keys.reset();
1606
keys_in_use_for_query.reset();
1607
keys_in_use_for_group_by.reset();
1608
keys_in_use_for_order_by.reset();
1610
memset(quick_rows, 0, sizeof(ha_rows) * MAX_KEY);
1611
memset(const_key_parts, 0, sizeof(ha_rows) * MAX_KEY);
1613
memset(quick_key_parts, 0, sizeof(unsigned int) * MAX_KEY);
1614
memset(quick_n_ranges, 0, sizeof(unsigned int) * MAX_KEY);
1638
1617
/*****************************************************************************
1654
1633
print them to the .err log
1656
1635
if (error != HA_ERR_LOCK_DEADLOCK && error != HA_ERR_LOCK_WAIT_TIMEOUT)
1657
errmsg_printf(error::ERROR, _("Got error %d when reading table '%s'"),
1636
errmsg_printf(ERRMSG_LVL_ERROR, _("Got error %d when reading table '%s'"),
1658
1637
error, getShare()->getPath());
1659
1638
print_error(error, MYF(0));
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
1714
} /* namespace drizzled */