Skip to content
Open
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
4 changes: 2 additions & 2 deletions lib/benchmark-common.sh
Original file line number Diff line number Diff line change
Expand Up @@ -348,7 +348,7 @@ bench_concurrent_qps() {

# Read the same query file that bench_run_query consumed.
local queries=() q
while IFS= read -r q; do
while IFS= read -r q || [ -n "$q" ]; do

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm trying to read this single line of code, and it is not obvious to me. Will it be an endless loop after consuming all results?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

read returns status 1 when it reaches EOF before a newline, but it still assigns the partial line to q. Since while A || B runs when either condition succeeds, [ -n "$q" ] is true for that final query and the body runs.

On the next condition check, the file descriptor is already at EOF. read returns 1 with no data and q becomes empty, so [ -n "$q" ] is also false. The while condition is therefore false and the loop exits.

[ -z "$q" ] && continue
queries+=("$q")
done < "$BENCH_QUERIES_FILE"
Expand Down Expand Up @@ -476,7 +476,7 @@ bench_main() {

: > result.csv
local query_num=1
while IFS= read -r query; do
while IFS= read -r query || [ -n "$query" ]; do
# Skip empty lines.
[ -z "$query" ] && continue
bench_run_query "$query" "$query_num"
Expand Down