Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(tianmu):the data is wrong when altering table after deleting.(#1199) #1272

Merged
merged 1 commit into from
Feb 16, 2023
Merged
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
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
1 change: 1 addition & 0 deletions storage/tianmu/core/tianmu_table.h
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,7 @@ class TianmuTable final : public JustATable {
void MoveToRow(int64_t row_id);
int64_t GetCurrentRowId() const { return position; }
bool Inited() const { return table != nullptr; }
std::vector<TianmuAttr *> GetAttrs() { return attrs; }

private:
void FetchValues();
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 @@ -1107,10 +1107,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 @@ -1369,8 +1373,19 @@ int ha_tianmu::fill_row(uchar *buf) {
std::memcpy(buffer.get(), table->record[0], table->s->reclength);
}

for (uint col_id = 0; col_id < table->s->fields; col_id++)
core::Engine::ConvertToField(table->field[col_id], *(table_new_iter_.GetData(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], *(table_new_iter_.GetData(col_id)),
wisehead marked this conversation as resolved.
Show resolved Hide resolved
&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;
}
}

if (buf != table->record[0]) {
std::memcpy(buf, table->record[0], table->s->reclength);
Expand Down