Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit9f34cae

Browse files
committed
psql: Fix \watch when using interval values less than 1ms
Attempting to use an interval of time less than 1ms would cause \watchto hang. This was confusing, so let's change the logic so as aninterval lower than 1ms behaves the same as 0.Comments are added to mention that the internals of do_watch() hadbetter rely on "sleep_ms", the interval value in milliseconds. While onit, this commit adds a test to check the behavior of interval valuesless than 1ms.\watch hanging for interval values less than 1ms existed before6f9ee74, that has changed the code to support an interval value of0.Reported-by: Heikki LinnakangasAuthor: Andrey M. Borodin, Michael PaquierDiscussion:https://postgr.es/m/88445e0e-3156-4b9d-afae-9a1a7b1631f6@iki.fiBackpatch-through: 16
1 parent35a015a commit9f34cae

File tree

2 files changed

+16
-5
lines changed

2 files changed

+16
-5
lines changed

‎src/bin/psql/command.c

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5359,6 +5359,10 @@ do_shell(const char *command)
53595359
*
53605360
* We break this out of exec_command to avoid having to plaster "volatile"
53615361
* onto a bunch of exec_command's variables to silence stupider compilers.
5362+
*
5363+
* "sleep" is the amount of time to sleep during each loop, measured in
5364+
* seconds. The internals of this function should use "sleep_ms" for
5365+
* precise sleep time calculations.
53625366
*/
53635367
staticbool
53645368
do_watch(PQExpBufferquery_buf,doublesleep,intiter,intmin_rows)
@@ -5484,10 +5488,10 @@ do_watch(PQExpBuffer query_buf, double sleep, int iter, int min_rows)
54845488

54855489
if (user_title)
54865490
snprintf(title,title_len,_("%s\t%s (every %gs)\n"),
5487-
user_title,timebuf,sleep);
5491+
user_title,timebuf,sleep_ms /1000.0);
54885492
else
54895493
snprintf(title,title_len,_("%s (every %gs)\n"),
5490-
timebuf,sleep);
5494+
timebuf,sleep_ms /1000.0);
54915495
myopt.title=title;
54925496

54935497
/* Run the query and print out the result */
@@ -5508,7 +5512,8 @@ do_watch(PQExpBuffer query_buf, double sleep, int iter, int min_rows)
55085512
if (pagerpipe&&ferror(pagerpipe))
55095513
break;
55105514

5511-
if (sleep==0)
5515+
/* Tight loop, no wait needed */
5516+
if (sleep_ms==0)
55125517
continue;
55135518

55145519
#ifdefWIN32

‎src/bin/psql/t/001_basic.pl

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -352,8 +352,14 @@ sub psql_fails_like
352352

353353
# Check \watch
354354
# Note: the interval value is parsed with locale-aware strtod()
355-
psql_like($node,sprintf('SELECT 1 \watch c=3 i=%g', 0.01),
356-
qr/1\n1\n1/,'\watch with 3 iterations');
355+
psql_like(
356+
$node,sprintf('SELECT 1 \watch c=3 i=%g', 0.01),
357+
qr/1\n1\n1/,'\watch with 3 iterations, interval of 0.01');
358+
359+
# Sub-millisecond wait works, equivalent to 0.
360+
psql_like(
361+
$node,sprintf('SELECT 1 \watch c=3 i=%g', 0.0001),
362+
qr/1\n1\n1/,'\watch with 3 iterations, interval of 0.0001');
357363

358364
# Check \watch minimum row count
359365
psql_fails_like(

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp