46
46
#include "drizzled/charset.h"
47
47
#include "drizzled/internal/m_string.h"
48
48
#include "plugin/myisam/myisam.h"
49
#include "drizzled/plugin/storage_engine.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"
57
#include "drizzled/table/instance.h"
62
59
#include "drizzled/table_proto.h"
66
extern pid_t current_pid;
69
67
extern plugin::StorageEngine *heap_engine;
70
68
extern plugin::StorageEngine *myisam_engine;
72
70
/* Functions defined in this cursor */
72
void open_table_error(TableShare *share, int error, int db_errno,
73
myf errortype, int errarg);
74
75
/*************************************************************************/
76
77
// @note this should all be the destructor
337
bool check_db_name(Session *session, identifier::Schema &schema_identifier)
336
bool check_db_name(Session *session, SchemaIdentifier &schema_identifier)
339
if (not plugin::Authorization::isAuthorized(session->user(), schema_identifier))
338
if (not plugin::Authorization::isAuthorized(session->getSecurityContext(), schema_identifier))
522
521
We must set bit in read set as update_auto_increment() is using the
523
522
store() to check overflow of auto_increment values
525
setReadSet(found_next_number_field->position());
526
setWriteSet(found_next_number_field->position());
524
setReadSet(found_next_number_field->field_index);
525
setWriteSet(found_next_number_field->field_index);
527
526
if (getShare()->next_number_keypart)
528
527
mark_columns_used_by_index_no_reset(getShare()->next_number_index);
622
621
/* Merge keys is all keys that had a column refered to in the query */
623
622
if (is_overlapping(merge_keys, (*reg_field)->part_of_key))
624
setReadSet((*reg_field)->position());
623
setReadSet((*reg_field)->field_index);
886
885
table->getMutableShare()->blob_field.resize(field_count+1);
887
886
uint32_t *blob_field= &table->getMutableShare()->blob_field[0];
887
table->getMutableShare()->blob_ptr_size= portable_sizeof_char_ptr;
888
888
table->getMutableShare()->db_low_byte_first=1; // True for HEAP and MyISAM
889
889
table->getMutableShare()->table_charset= param->table_charset;
890
890
table->getMutableShare()->keys_for_keyread.reset();
1012
1012
group_null_items++;
1013
1013
new_field->flags|= GROUP_FLAG;
1015
new_field->setPosition(fieldnr++);
1015
new_field->field_index= fieldnr++;
1016
1016
*(reg_field++)= new_field;
1018
1018
if (!--hidden_field_count)
1035
1035
field_count= fieldnr;
1037
1037
*blob_field= 0; // End marker
1038
table->getMutableShare()->setFieldSize(field_count);
1038
table->getMutableShare()->fields= field_count;
1040
1040
/* If result table is small; use a heap */
1041
1041
/* future: storage engine selection can be made dynamic? */
1476
True if the table's input and output record buffers are comparable using
1477
compare_records(TABLE*).
1479
bool Table::records_are_comparable()
1481
return ((getEngine()->check_flag(HTON_BIT_PARTIAL_COLUMN_READ) == 0) ||
1482
write_set->is_subset_of(*read_set));
1486
Compares the input and outbut record buffers of the table to see if a row
1487
has changed. The algorithm iterates over updated columns and if they are
1488
nullable compares NULL bits in the buffer before comparing actual
1489
data. Special care must be taken to compare only the relevant NULL bits and
1490
mask out all others as they may be undefined. The storage engine will not
1491
and should not touch them.
1493
@param table The table to evaluate.
1495
@return true if row has changed.
1496
@return false otherwise.
1498
bool Table::compare_records()
1500
if (getEngine()->check_flag(HTON_BIT_PARTIAL_COLUMN_READ) != 0)
1503
Storage engine may not have read all columns of the record. Fields
1504
(including NULL bits) not in the write_set may not have been read and
1505
can therefore not be compared.
1507
for (Field **ptr= this->field ; *ptr != NULL; ptr++)
1510
if (write_set->test(f->position()))
1512
if (f->real_maybe_null())
1514
unsigned char null_byte_index= f->null_ptr - record[0];
1516
if (((record[0][null_byte_index]) & f->null_bit) !=
1517
((record[1][null_byte_index]) & f->null_bit))
1520
if (f->cmp_binary_offset(getShare()->rec_buff_length))
1528
The storage engine has read all columns, so it's safe to compare all bits
1529
including those not in the write_set. This is cheaper than the
1530
field-by-field comparison done above.
1475
/* Return false if row hasn't changed */
1477
bool Table::compare_record()
1532
1479
if (not getShare()->blob_fields + getShare()->hasVariableWidth())
1533
// Fixed-size record: do bitwise comparison of the records
1534
1480
return memcmp(this->getInsertRecord(), this->getUpdateRecord(), (size_t) getShare()->getRecordLength());
1536
1482
/* Compare null bits */
1537
1483
if (memcmp(null_flags, null_flags + getShare()->rec_buff_length, getShare()->null_bytes))
1538
1484
return true; /* Diff in NULL value */
1540
1486
/* Compare updated fields */
1541
1487
for (Field **ptr= field ; *ptr ; ptr++)
1543
if (isWriteSet((*ptr)->position()) &&
1489
if (isWriteSet((*ptr)->field_index) &&
1544
1490
(*ptr)->cmp_binary_offset(getShare()->rec_buff_length))
1648
1594
quick_condition_rows(0),
1649
1595
timestamp_field_type(TIMESTAMP_NO_AUTO_SET),
1656
1598
record[0]= (unsigned char *) 0;
1657
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);
1660
1617
/*****************************************************************************
1676
1633
print them to the .err log
1678
1635
if (error != HA_ERR_LOCK_DEADLOCK && error != HA_ERR_LOCK_WAIT_TIMEOUT)
1679
errmsg_printf(error::ERROR, _("Got error %d when reading table '%s'"),
1636
errmsg_printf(ERRMSG_LVL_ERROR, _("Got error %d when reading table '%s'"),
1680
1637
error, getShare()->getPath());
1681
1638
print_error(error, MYF(0));
1758
Is this instance of the table should be reopen or represents a name-lock?
1760
bool Table::needs_reopen_or_name_lock() const
1762
return getShare()->getVersion() != refresh_version;
1765
uint32_t Table::index_flags(uint32_t idx) const
1767
return getShare()->getEngine()->index_flags(getShare()->getKeyInfo(idx).algorithm);
1770
void Table::print_error(int error, myf errflag) const
1772
getShare()->getEngine()->print_error(error, errflag, *this);
1775
1714
} /* namespace drizzled */