Re: coverage increase for worker_spi

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Alvaro Herrera <alvherre(at)2ndquadrant(dot)com>
Cc: Pg Hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org>
Subject: Re: coverage increase for worker_spi
Date: 2019-05-30 17:46:18
Message-ID: 52058.1559238378@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Alvaro Herrera <alvherre(at)2ndquadrant(dot)com> writes:
> On 2019-May-30, Tom Lane wrote:
>> Hm, I don't understand how this works at all:
>>
>> + PERFORM pg_sleep(CASE WHEN count(*) = 0 THEN 0 ELSE 0.1 END)
>> + FROM schema1.counted WHERE type = 'delta';
>> + GET DIAGNOSTICS count = ROW_COUNT;
>>
>> Given that it uses an aggregate, the ROW_COUNT must always be 1, no?

> Well, I was surprised to see the count(*) work there as an argument for
> pg_sleep there at all frankly (maybe we are sleeping 0.1s more than we
> really need, per your observation), but the row_count is concerned with
> rows that have type = 'delta', which are deleted by the bgworker. So
> the test script job is done when the bgworker has run once through its
> loop.

No, the row_count is going to report the number of rows returned by
the aggregate query, which is going to be one row, independently
of how many rows went into the aggregate.

regression=# do $$
declare c int;
begin
perform count(*) from tenk1;
get diagnostics c = row_count;
raise notice 'c = %', c;
end$$;
psql: NOTICE: c = 1
DO
regression=# do $$
declare c int;
begin
perform count(*) from tenk1 where false;
get diagnostics c = row_count;
raise notice 'c = %', c;
end$$;
psql: NOTICE: c = 1
DO

I think you want to capture the actual aggregate output rather than
relying on row_count:

regression=# do $$
declare c int;
begin
c := count(*) from tenk1;
raise notice 'c = %', c;
end$$;
psql: NOTICE: c = 10000
DO
regression=# do $$
declare c int;
begin
c := count(*) from tenk1 where false;
raise notice 'c = %', c;
end$$;
psql: NOTICE: c = 0
DO

regards, tom lane

In response to

Browse pgsql-hackers by date

  From Date Subject
Next Message Alvaro Herrera 2019-05-30 17:52:20 coverage additions
Previous Message Devansh Gupta 2019-05-30 17:39:18 Applicant for Google Season of Documentation