Skip to content

Commit

Permalink
fix(tianmu):the data is wrong when altering table after deleting.(sto…
Browse files Browse the repository at this point in the history
…neatom#1199)

Because the records which was deleted is not filtered in fill_row().
  • Loading branch information
DandreChen authored and konghaiya committed Mar 7, 2023
1 parent f17d56f commit d0aeebe
Show file tree
Hide file tree
Showing 4 changed files with 76 additions and 6 deletions.
28 changes: 28 additions & 0 deletions mysql-test/suite/tianmu/r/alter_delete.result
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
DROP DATABASE IF EXISTS alter_delete;
CREATE DATABASE alter_delete;
USE alter_delete;
CREATE TABLE ttt1(id INT,name VARCHAR(5));
INSERT INTO ttt1 VALUES(0,"XXX"),(1,'AAA'),(2,'BBB');
SELECT * FROM ttt1;
id name
0 XXX
1 AAA
2 BBB
DELETE FROM ttt1 WHERE id=1;
SELECT * FROM ttt1;
id name
0 XXX
2 BBB
ALTER TABLE ttt1 CONVERT TO CHARACTER SET utf8;
SELECT * FROM ttt1;
id name
0 XXX
2 BBB
SHOW CREATE TABLE ttt1;
Table Create Table
ttt1 CREATE TABLE `ttt1` (
`id` int(11) DEFAULT NULL,
`name` varchar(5) DEFAULT NULL
) ENGINE=TIANMU DEFAULT CHARSET=utf8
DROP TABLE ttt1;
DROP DATABASE alter_delete;
29 changes: 29 additions & 0 deletions mysql-test/suite/tianmu/t/alter_delete.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
--source include/have_tianmu.inc

--disable_warnings
DROP DATABASE IF EXISTS alter_delete;
--enable_warnings

CREATE DATABASE alter_delete;

USE alter_delete;

CREATE TABLE ttt1(id INT,name VARCHAR(5));

INSERT INTO ttt1 VALUES(0,"XXX"),(1,'AAA'),(2,'BBB');

SELECT * FROM ttt1;

DELETE FROM ttt1 WHERE id=1;

SELECT * FROM ttt1;

ALTER TABLE ttt1 CONVERT TO CHARACTER SET utf8;

SELECT * FROM ttt1;

SHOW CREATE TABLE ttt1;

DROP TABLE ttt1;

DROP DATABASE alter_delete;
4 changes: 1 addition & 3 deletions storage/tianmu/core/dimension_group.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -353,9 +353,7 @@ int DimensionGroupMaterialized::DGMaterializedIterator::GetNextPackrow(int dim,
if (next_pack[dim] >= no_obj || uint64_t(next_pack[dim]) >= end_block)
return -1;
uint64_t ahead_pos = 0;
// cout << "dim " << dim << ", " << next_pack[dim] << " -> " <<
// ahead1[dim] << " " <<
// ahead2[dim] << " " << ahead3[dim] << " (" << ahead << ")" << endl;

if (ahead == 1)
ahead_pos = t[dim]->Get64InsideBlock(next_pack[dim]);
else if (ahead == 2 && ahead1[dim] != -1)
Expand Down
21 changes: 18 additions & 3 deletions storage/tianmu/handler/ha_tianmu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -971,10 +971,14 @@ int ha_tianmu::rnd_next(uchar *buf) {
int ret = HA_ERR_END_OF_FILE;
try {
table->status = 0;
if (fill_row(buf) == HA_ERR_END_OF_FILE) {
ret = fill_row(buf);
if (ret == HA_ERR_END_OF_FILE) {
table->status = STATUS_NOT_FOUND;
DBUG_RETURN(ret);
}
if (ret == HA_ERR_RECORD_DELETED) {
DBUG_RETURN(ret);
}
ret = 0;
} catch (std::exception &e) {
my_message(static_cast<int>(common::ErrorCode::UNKNOWN_ERROR), e.what(), MYF(0));
Expand Down Expand Up @@ -1231,8 +1235,19 @@ int ha_tianmu::fill_row(uchar *buf) {
std::memcpy(buffer.get(), table->record[0], table->s->reclength);
}
if (iterator_->IsBase()) {
for (uint col_id = 0; col_id < table->s->fields; col_id++)
core::Engine::ConvertToField(table->field[col_id], *(iterator_->GetBaseData(col_id)), &blob_buffers_[col_id]);
for (uint col_id = 0; col_id < table->s->fields; col_id++) {
// when ConvertToField() return true, to judge whether this line has been deleted.
// if this line has been deleted, data will not be copied.
if (core::Engine::ConvertToField(table->field[col_id], *(iterator_->GetBaseData(col_id)),
&blob_buffers_[col_id]) &&
(table_new_iter_.GetAttrs().size() > col_id) &&
table_new_iter_.GetAttrs()[col_id]->IsDelete(table_new_iter_.GetCurrentRowId())) {
current_position_ = table_new_iter_.GetCurrentRowId();
table_new_iter_++;
dbug_tmp_restore_column_map(table->write_set, org_bitmap);
return HA_ERR_RECORD_DELETED;
}
}
} else {
std::string delta_record = iterator_->GetDeltaData();
core::Engine::DecodeInsertRecord(delta_record.data(), delta_record.size(), table->field);
Expand Down

0 comments on commit d0aeebe

Please sign in to comment.