Re: coverage increase for worker_spi

Поиск
Список
Период
Сортировка
От Tom Lane
Тема Re: coverage increase for worker_spi
Дата
Msg-id 52058.1559238378@sss.pgh.pa.us
обсуждение исходный текст
Ответ на Re: coverage increase for worker_spi  (Alvaro Herrera <alvherre@2ndquadrant.com>)
Список pgsql-hackers
Alvaro Herrera <alvherre@2ndquadrant.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



В списке pgsql-hackers по дате отправления:

Предыдущее
От: Devansh Gupta
Дата:
Сообщение: Applicant for Google Season of Documentation
Следующее
От: Alvaro Herrera
Дата:
Сообщение: coverage additions