Skip to content
This repository was archived by the owner on Mar 10, 2020. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions mysql-test/mytile/r/auto_increment.result
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#Primary Key Auto Increment Support Test
CREATE TABLE t1 (
column1 integer auto_increment,
column2 varchar(255),
primary key(column1)
) ENGINE=mytile;
INSERT INTO t1(column2) VALUES ('aHR0cHM6Ly9naXRodWIuY29tL1NoZWxudXR0Mi9jcnVuY2g='), ('dmFsdWUy'), ('dmFsdWU');
select column1, column2 from t1 ORDER BY column1;
column1 column2
1 aHR0cHM6Ly9naXRodWIuY29tL1NoZWxudXR0Mi9jcnVuY2g=
2 dmFsdWUy
3 dmFsdWU
INSERT INTO t1(column2) VALUES ('row4');
select column1, column2 from t1 ORDER BY column1;
column1 column2
1 aHR0cHM6Ly9naXRodWIuY29tL1NoZWxudXR0Mi9jcnVuY2g=
2 dmFsdWUy
3 dmFsdWU
4 row4
DROP TABLE t1;
11 changes: 11 additions & 0 deletions mysql-test/mytile/t/auto_increment.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
--echo #Primary Key Auto Increment Support Test
CREATE TABLE t1 (
column1 integer auto_increment,
column2 varchar(255),
primary key(column1)
) ENGINE=mytile;
INSERT INTO t1(column2) VALUES ('aHR0cHM6Ly9naXRodWIuY29tL1NoZWxudXR0Mi9jcnVuY2g='), ('dmFsdWUy'), ('dmFsdWU');
select column1, column2 from t1 ORDER BY column1;
INSERT INTO t1(column2) VALUES ('row4');
select column1, column2 from t1 ORDER BY column1;
DROP TABLE t1;
96 changes: 64 additions & 32 deletions mytile/ha_mytile.cc
Original file line number Diff line number Diff line change
Expand Up @@ -749,43 +749,62 @@ int tile::mytile::index_read_idx_map(uchar *buf, uint idx, const uchar *key, key
//for (auto mapItem : this->map) {
std::vector<uchar> prevKey;
std::vector<uchar> itemKey;
while (mapItemIterator != this->map->end()) {
// Only check the item if it is not deleted
if (!mapItemIterator->get<bool>(MYTILE_DELETE_ATTRIBUTE)) {
itemKey = mapItemIterator->key<std::vector<uchar>>();
if (!tile::cmpKeys(key, itemKey.data(), table->s->key_info + idx)) {
switch (find_flag) {
// Currently only support AFTER, BEFORE and EXACT.
case HA_READ_AFTER_KEY:
mapItemIterator.operator++();
itemKey = mapItemIterator->key<std::vector<uchar>>();
break;
case HA_READ_BEFORE_KEY:
itemKey = prevKey;
break;
case HA_READ_KEY_EXACT:
break;
case HA_READ_KEY_OR_NEXT:
case HA_READ_KEY_OR_PREV:
case HA_READ_PREFIX:
case HA_READ_PREFIX_LAST:
case HA_READ_PREFIX_LAST_OR_PREV:
case HA_READ_MBR_CONTAIN:
case HA_READ_MBR_INTERSECT:
case HA_READ_MBR_WITHIN:
case HA_READ_MBR_DISJOINT:
case HA_READ_MBR_EQUAL:
/* This flag is not used by the SQL layer, so we don't support it yet. */
rc = HA_ERR_UNSUPPORTED;
break;

// TODO: The keys are ordered, but for auto increment this happens to work by the nature of auto increment
if(key == NULL) {
sql_print_information("find_flag = %d", find_flag);
if(find_flag == HA_READ_PREFIX_LAST) {
while (mapItemIterator != this->map->end()) {
itemKey = mapItemIterator->key<std::vector<uchar>>();
sql_print_information("key found: %s", itemKey.data());
prevKey = itemKey;
mapItemIterator.operator++();
}
itemKey = prevKey;
sql_print_information("key found final size of: %s", itemKey.size());
}
} else { //Key is not null
while (mapItemIterator != this->map->end()) {
// Only check the item if it is not deleted
if (!mapItemIterator->get<bool>(MYTILE_DELETE_ATTRIBUTE)) {
itemKey = mapItemIterator->key<std::vector<uchar>>();
if (!tile::cmpKeys(key, itemKey.data(), table->s->key_info + idx)) {
switch (find_flag) {
// Currently only support AFTER, BEFORE and EXACT.
case HA_READ_AFTER_KEY:
mapItemIterator.operator++();
itemKey = mapItemIterator->key<std::vector<uchar>>();
break;
case HA_READ_BEFORE_KEY:
itemKey = prevKey;
break;
case HA_READ_KEY_EXACT:
break;
case HA_READ_KEY_OR_NEXT:
case HA_READ_KEY_OR_PREV:
case HA_READ_PREFIX:
case HA_READ_PREFIX_LAST:
case HA_READ_PREFIX_LAST_OR_PREV:
case HA_READ_MBR_CONTAIN:
case HA_READ_MBR_INTERSECT:
case HA_READ_MBR_WITHIN:
case HA_READ_MBR_DISJOINT:
case HA_READ_MBR_EQUAL:
/* This flag is not used by the SQL layer, so we don't support it yet. */
rc = HA_ERR_UNSUPPORTED;
break;
}
break;
}
break;
prevKey = itemKey;
}
prevKey = itemKey;
mapItemIterator.operator++();
}
mapItemIterator.operator++();
}

if(itemKey.size() == 0)
rc = HA_ERR_KEY_NOT_FOUND;

if (!rc) {
tiledb::MapItem mapItem = this->map->get_item(itemKey);
if (mapItem.good()) {
Expand All @@ -798,6 +817,18 @@ int tile::mytile::index_read_idx_map(uchar *buf, uint idx, const uchar *key, key
DBUG_RETURN(rc);
}

int tile::mytile::index_last(uchar *buf) {
DBUG_ENTER("tile::mytile::index_last");

int error = index_read_map(buf, NULL, 0, HA_READ_BEFORE_KEY);

/* MySQL does not seem to allow this to return HA_ERR_KEY_NOT_FOUND */

if (error == HA_ERR_KEY_NOT_FOUND) {
error = HA_ERR_END_OF_FILE;
}
DBUG_RETURN(error);
}
/**
* Store a lock, we aren't using table or row locking at this point.
* @param thd
Expand Down Expand Up @@ -867,6 +898,7 @@ ha_rows tile::mytile::records_in_range(uint inx, key_range *min_key, key_range *
ulonglong tile::mytile::table_flags(void) const {
DBUG_ENTER("tile::mytile::table_flags");
DBUG_RETURN(HA_REC_NOT_IN_SEQ | HA_CAN_SQL_HANDLER | HA_NULL_IN_KEY | HA_REQUIRE_PRIMARY_KEY
| HA_AUTO_PART_KEY | HA_NO_TRANSACTIONS
| HA_CAN_BIT_FIELD | HA_FILE_BASED | HA_BINLOG_ROW_CAPABLE | HA_BINLOG_STMT_CAPABLE);
};

Expand Down
2 changes: 2 additions & 0 deletions mytile/ha_mytile.h
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,8 @@ namespace tile {
int index_read_idx_map(uchar *buf, uint idx, const uchar *key, key_part_map keypart_map,
enum ha_rkey_function find_flag) override;

int index_last(uchar *buf);

THR_LOCK_DATA **store_lock(THD *thd, THR_LOCK_DATA **to, enum thr_lock_type lock_type) override;

int external_lock(THD *thd, int lock_type) override;
Expand Down