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

Commit6331972

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 parent64635c8 commit6331972

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
@@ -5142,6 +5142,10 @@ do_shell(const char *command)
51425142
*
51435143
* We break this out of exec_command to avoid having to plaster "volatile"
51445144
* onto a bunch of exec_command's variables to silence stupider compilers.
5145+
*
5146+
* "sleep" is the amount of time to sleep during each loop, measured in
5147+
* seconds. The internals of this function should use "sleep_ms" for
5148+
* precise sleep time calculations.
51455149
*/
51465150
staticbool
51475151
do_watch(PQExpBufferquery_buf,doublesleep,intiter)
@@ -5267,10 +5271,10 @@ do_watch(PQExpBuffer query_buf, double sleep, int iter)
52675271

52685272
if (user_title)
52695273
snprintf(title,title_len,_("%s\t%s (every %gs)\n"),
5270-
user_title,timebuf,sleep);
5274+
user_title,timebuf,sleep_ms /1000.0);
52715275
else
52725276
snprintf(title,title_len,_("%s (every %gs)\n"),
5273-
timebuf,sleep);
5277+
timebuf,sleep_ms /1000.0);
52745278
myopt.title=title;
52755279

52765280
/* Run the query and print out the result */
@@ -5290,7 +5294,8 @@ do_watch(PQExpBuffer query_buf, double sleep, int iter)
52905294
if (pagerpipe&&ferror(pagerpipe))
52915295
break;
52925296

5293-
if (sleep==0)
5297+
/* Tight loop, no wait needed */
5298+
if (sleep_ms==0)
52945299
continue;
52955300

52965301
#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 errors
359365
psql_fails_like(

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp