mirror of
https://github.com/GreptimeTeam/greptimedb.git
synced 2026-12-03 07:55:25 +00:00
* test(mito): cover two puts older than a delete in flat last_non_null dedup test_flat_last_non_null_strategy_delete_middle now has a second put older than the delete at ts 3. Its field1 must not fill the null field1 of the newest put. This fails on main: the row reads back as (31, 33). The merge_mode sqlness case deletes a row written by two puts and rewrites it with a NULL field while another series sits in an SST. On main the NULL reads back as the value from before the delete. Signed-off-by: dayan02dev <pawarudayan92@gmail.com> * fix(mito): keep the delete barrier across flat last_non_null merges FlatLastNonNull::dedup_by_partitions returned only whether the last range has a delete. When the buffered row and the next batch formed a single range without a delete row, the barrier passed in from the previous batch was used for that merge but not returned, so the next put older than the delete filled the null fields again. Signed-off-by: dayan02dev <pawarudayan92@gmail.com> * docs(mito): note the inherited delete in flat last_non_null dedup comments Signed-off-by: dayan02dev <pawarudayan92@gmail.com> --------- Signed-off-by: dayan02dev <pawarudayan92@gmail.com>
125 lines
3.4 KiB
SQL
125 lines
3.4 KiB
SQL
create table if not exists last_non_null_table(
|
|
host string,
|
|
ts timestamp,
|
|
cpu double,
|
|
memory double,
|
|
TIME INDEX (ts),
|
|
PRIMARY KEY(host)
|
|
)
|
|
engine=mito
|
|
with('merge_mode'='last_non_null');
|
|
|
|
INSERT INTO last_non_null_table VALUES ('host1', 0, 0, NULL), ('host2', 1, NULL, 1);
|
|
|
|
INSERT INTO last_non_null_table VALUES ('host1', 0, NULL, 10), ('host2', 1, 11, NULL);
|
|
|
|
SELECT * from last_non_null_table ORDER BY host, ts;
|
|
|
|
INSERT INTO last_non_null_table VALUES ('host1', 0, 20, NULL);
|
|
|
|
SELECT * from last_non_null_table ORDER BY host, ts;
|
|
|
|
INSERT INTO last_non_null_table VALUES ('host1', 0, NULL, NULL);
|
|
|
|
SELECT * from last_non_null_table ORDER BY host, ts;
|
|
|
|
DROP TABLE last_non_null_table;
|
|
|
|
create table if not exists last_row_table(
|
|
host string,
|
|
ts timestamp,
|
|
cpu double,
|
|
memory double,
|
|
TIME INDEX (ts),
|
|
PRIMARY KEY(host)
|
|
)
|
|
engine=mito
|
|
with('merge_mode'='last_row');
|
|
|
|
INSERT INTO last_row_table VALUES ('host1', 0, 0, NULL), ('host2', 1, NULL, 1);
|
|
|
|
INSERT INTO last_row_table VALUES ('host1', 0, NULL, 10), ('host2', 1, 11, NULL);
|
|
|
|
SELECT * from last_row_table ORDER BY host, ts;
|
|
|
|
DROP TABLE last_row_table;
|
|
|
|
CREATE TABLE IF NOT EXISTS `delete_between` (
|
|
`time` TIMESTAMP(0) NOT NULL,
|
|
`code` STRING NULL,
|
|
`name` STRING NULL,
|
|
`status` TINYINT NULL,
|
|
TIME INDEX (`time`),
|
|
PRIMARY KEY (`code`)
|
|
) ENGINE=mito WITH(
|
|
merge_mode = 'last_non_null'
|
|
);
|
|
|
|
INSERT INTO `delete_between` (`time`, `code`, `name`, `status`) VALUES ('2024-11-26 10:00:00', 'achn', '1.png', 0);
|
|
INSERT INTO `delete_between` (`time`, `code`, `name`, `status`) VALUES ('2024-11-26 10:01:00', 'achn', '2.png', 0);
|
|
INSERT INTO `delete_between` (`time`, `code`, `name`, `status`) VALUES ('2024-11-26 10:02:00', 'achn', '3.png', 1);
|
|
|
|
SELECT * FROM `delete_between`;
|
|
|
|
DELETE FROM `delete_between`;
|
|
|
|
INSERT INTO `delete_between` (`time`, `code`, `name`) VALUES ('2024-11-26 10:00:00', 'achn', '1.png');
|
|
INSERT INTO `delete_between` (`time`, `code`, `name`) VALUES ('2024-11-26 10:01:00', 'achn', '2.png');
|
|
INSERT INTO `delete_between` (`time`, `code`, `name`) VALUES ('2024-11-26 10:02:00', 'achn', '3.png');
|
|
|
|
SELECT * FROM `delete_between`;
|
|
|
|
DROP TABLE `delete_between`;
|
|
|
|
CREATE TABLE IF NOT EXISTS `delete_reinsert` (
|
|
`host` STRING,
|
|
`ts` TIMESTAMP TIME INDEX,
|
|
`cpu` DOUBLE NULL,
|
|
`mem` BIGINT NULL,
|
|
PRIMARY KEY (`host`)
|
|
) ENGINE=mito WITH(
|
|
merge_mode = 'last_non_null'
|
|
);
|
|
|
|
INSERT INTO `delete_reinsert` VALUES ('h2', 2000, 1.0, NULL);
|
|
|
|
ADMIN FLUSH_TABLE('delete_reinsert');
|
|
|
|
INSERT INTO `delete_reinsert` VALUES ('h1', 1000, 1.0, NULL);
|
|
|
|
INSERT INTO `delete_reinsert` VALUES ('h1', 1000, NULL, 20);
|
|
|
|
DELETE FROM `delete_reinsert` WHERE `host` = 'h1' AND `ts` = 1000;
|
|
|
|
INSERT INTO `delete_reinsert` VALUES ('h1', 2000, NULL, NULL);
|
|
|
|
INSERT INTO `delete_reinsert` VALUES ('h1', 1000, NULL, 10);
|
|
|
|
-- Values written before the delete must not fill the NULL fields.
|
|
SELECT * FROM `delete_reinsert` ORDER BY `host`, `ts`;
|
|
|
|
DROP TABLE `delete_reinsert`;
|
|
|
|
-- SQLNESS REPLACE (\sat\sline\s\d+\scolumn\s\d+)
|
|
create table if not exists invalid_merge_mode(
|
|
host string,
|
|
ts timestamp,
|
|
cpu double,
|
|
memory double,
|
|
TIME INDEX (ts),
|
|
PRIMARY KEY(host)
|
|
)
|
|
engine=mito
|
|
with('merge_mode'='first_row');
|
|
|
|
create table if not exists invalid_merge_mode(
|
|
host string,
|
|
ts timestamp,
|
|
cpu double,
|
|
memory double,
|
|
TIME INDEX (ts),
|
|
PRIMARY KEY(host)
|
|
)
|
|
engine=mito
|
|
with('merge_mode'='last_non_null', 'append_mode'='true');
|