Skip to content

Commit

Permalink
fix(query): increase state_rows in copy agg state rows (#17252)
Browse files Browse the repository at this point in the history
* fix(query): increase state_rows in copy agg state rows

* fix(query): increase state_rows in copy agg state rows

* fix(query): increase state_rows in copy agg state rows
  • Loading branch information
sundy-li committed Jan 13, 2025
1 parent 6294fb9 commit 7af80b1
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/query/expression/src/aggregate/payload.rs
Original file line number Diff line number Diff line change
Expand Up @@ -339,6 +339,7 @@ impl Payload {
)
}
page.rows += 1;
page.state_rows += 1;

if page.rows == page.capacity {
page = self.writable_page();
Expand Down
6 changes: 6 additions & 0 deletions tests/suites/0_stateless/20+_others/20_0022_agg_memory.result
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
executing 1
executing 2
executing 3
executing 4
executing 5
Memory usage difference is less than 5%
46 changes: 46 additions & 0 deletions tests/suites/0_stateless/20+_others/20_0022_agg_memory.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
#!/usr/bin/env bash
CURDIR=$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)
. "$CURDIR"/../../../shell_env.sh


## warmup
for i in `seq 1 2`;do
$BENDSQL_CLIENT_CONNECT --query="""
select number::string , max(number::string), min(number::string), count(distinct number) from numbers(10000000) group by 1 ignore_result;
"""
done


PIDS=($(pgrep databend-query))
BEFORE_MEM=0
for PID in "${PIDS[@]}"; do
MEM=$(ps -o rss= -p $PID | tail -n 1)
BEFORE_MEM=$((BEFORE_MEM + MEM))
done


for i in `seq 1 5`;do
echo "executing $i"
$BENDSQL_CLIENT_CONNECT --query="""
select number::string , max(number::string), min(number::string), count(distinct number) from numbers(10000000) group by 1 ignore_result;
"""
done

sleep 15


AFTER_MEM=0
for PID in "${PIDS[@]}"; do
MEM=$(ps -o rss= -p $PID | tail -n 1)
AFTER_MEM=$((AFTER_MEM + MEM))
done

# Calculate the difference in percentage
DIFF=$(awk -v before=$BEFORE_MEM -v after=$AFTER_MEM 'BEGIN {print (after-before)/before * 100}')

# Check if the difference is less than 5%
if (( $(awk -v diff=$DIFF 'BEGIN {print (diff < 5)}') )); then
echo "Memory usage difference is less than 5%"
else
echo "Memory usage difference is greater than 5%, before ${BEFORE_MEM} ${AFTER_MEM}"
fi

0 comments on commit 7af80b1

Please sign in to comment.