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 the wrong compare of catalog cache's mvcc #13440

Merged
merged 5 commits into from
Dec 13, 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
1 change: 1 addition & 0 deletions pkg/vm/engine/disttae/cache/catalog.go
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,7 @@ func (cc *CatalogCache) GetTable(tbl *TableItem) bool {
var tableId uint64
deleted := make(map[uint64]bool)
inserted := make(map[uint64]*TableItem)
tbl.Id = math.MaxUint64
cc.tables.data.Ascend(tbl, func(item *TableItem) bool {
if item.deleted && item.AccountId == tbl.AccountId &&
item.DatabaseId == tbl.DatabaseId && item.Name == tbl.Name {
Expand Down
11 changes: 7 additions & 4 deletions pkg/vm/engine/disttae/cache/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -225,13 +225,16 @@ func tableItemLess(a, b *TableItem) bool {
Then the item x3 will be lost. The TN will not know the table x3. It is wrong!
With sort on the table id, the item x3,x2,x1 will be reserved.
*/
if a.deleted && !b.deleted { //deleted item head first
// the logtail is unordered, so we need to sort the items by table id.
// the larger table id is created later.
if a.Id > b.Id {
return true
} else if !a.deleted && b.deleted {
}
if a.Id < b.Id {
return false
} else { //a.deleted && b.deleted || !a.deleted && !b.deleted
return a.Id < b.Id
}
// for the same table id, the delete item is head.
return a.deleted
}
return a.Ts.Greater(b.Ts)
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
create database if not exists test;
use test;
drop table if exists t;
begin;
create table t(a int);
alter table t add column b int;
commit;
select * from t;
a b
drop database test;
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
create database if not exists test;
use test;
drop table if exists t;
begin;
create table t(a int);
alter table t add column b int;
commit;
select * from t;
drop database test;
Loading