[Bug](sort)fix merge sorter might div zero when block bytes less than block rows (#15859)

If block bytes are bigger than the corresponding block's rows, then the avg_size_per_row would be zero. Which would end up diving zero in the following logic.
This commit is contained in:
AlexYue
2023-01-13 18:33:40 +08:00
committed by GitHub
parent e979cc444a
commit 049f8ad2f9
3 changed files with 35 additions and 1 deletions

View File

@ -43,7 +43,7 @@ Status MergeSorterState::add_sorted_block(Block& block) {
return Status::OK();
}
if (0 == avg_row_bytes_) {
avg_row_bytes_ = block.bytes() / rows;
avg_row_bytes_ = std::max((std::size_t)1, block.bytes() / rows);
spill_block_batch_size_ = (BLOCK_SPILL_BATCH_BYTES + avg_row_bytes_ - 1) / avg_row_bytes_;
}

View File

@ -0,0 +1,8 @@
-- This file is automatically generated. You should know what you did if you want to edit this
-- !sql --
0
2
2
3
3

View File

@ -78,4 +78,30 @@ suite("streamLoad_action") {
assertTrue(json.NumberLoadedRows > 0 && json.LoadBytes > 0)
}
}
// to test merge sort
sql """ DROP TABLE IF EXISTS B """
sql """
CREATE TABLE IF NOT EXISTS B
(
b_id int
)
DISTRIBUTED BY HASH(b_id) BUCKETS 1
PROPERTIES("replication_num" = "1");
"""
sql " INSERT INTO B values (1);"
qt_sql """
SELECT subq_0.`c1` AS c1
FROM
(SELECT version() AS c0,
ref_0.`id` AS c1
FROM test_streamload_action1 AS ref_0
LEFT JOIN B AS ref_9 ON (ref_0.`id` = ref_9.`b_id`)
WHERE ref_9.`b_id` IS NULL) AS subq_0
WHERE subq_0.`c0` IS NOT NULL
ORDER BY subq_0.`c1`, subq_0.`c0` DESC
LIMIT 5;
"""
}