Skip to content

Commit d92611d

Browse files
authored
fix: wrong calc of #rows of page in http handler. (#17839)
1 parent fc1257f commit d92611d

File tree

3 files changed

+15
-10
lines changed

3 files changed

+15
-10
lines changed

src/query/service/src/servers/http/v1/query/page_manager.rs

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,7 @@ impl PageManager {
134134
remain_rows: &mut usize,
135135
remain_size: &mut usize,
136136
) -> Result<()> {
137+
assert!(self.row_buffer.is_none());
137138
if block.is_empty() {
138139
return Ok(());
139140
}
@@ -148,10 +149,11 @@ impl PageManager {
148149
.map(|entry| entry.to_column(block.num_rows()))
149150
.collect_vec();
150151

152+
let block_memory_size = block.memory_size();
151153
let mut take_rows = min(
152154
*remain_rows,
153-
if block.memory_size() > *remain_size {
154-
(*remain_size * block.num_rows()) / block.memory_size()
155+
if block_memory_size > *remain_size {
156+
(*remain_size * block.num_rows()) / block_memory_size
155157
} else {
156158
block.num_rows()
157159
},
@@ -161,17 +163,15 @@ impl PageManager {
161163
take_rows = 1;
162164
}
163165

164-
// theoretically, it should always be smaller than the memory_size of the block.
165-
*remain_size -= min(
166-
*remain_size,
167-
take_rows * block.memory_size() / block.num_rows(),
168-
);
169-
*remain_rows -= take_rows;
170-
171166
if take_rows == block.num_rows() {
167+
// theoretically, it should always be smaller than the memory_size of the block.
168+
*remain_size -= min(*remain_size, block_memory_size);
169+
*remain_rows -= take_rows;
172170
serializer.append(columns, block.num_rows());
173-
self.row_buffer = None;
174171
} else {
172+
// Since not all rows of the block are used, either the size limit or the row limit must have been exceeded.
173+
// simply set any of remain_xxx to end the page.
174+
*remain_rows = 0;
175175
let fn_slice = |columns: &[Column], range: Range<usize>| {
176176
columns
177177
.iter()
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
1
22
1
33
0
4+
100000

tests/suites/1_stateful/09_http_handler/09_0004_large_row.sh

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,3 +16,7 @@ curl -s --header 'Content-Type: application/json' "127.0.0.1:8000/v1/query/$qid
1616

1717
curl -s --header 'Content-Type: application/json' "127.0.0.1:8000/v1/query/$qid/page/2" \
1818
-u root: | jq '.data | length'
19+
20+
# rows have diff sizes
21+
# row size > (max_size / max_rows) = 10M / 10000
22+
echo "SELECT repeat(number::string, 2000) from numbers(100000)" | $BENDSQL_CLIENT_CONNECT | wc -l | sed 's/ //g'

0 commit comments

Comments
 (0)