Negative cost is seen for plan node

From: Richard Guo <guofenglinux(at)gmail(dot)com>
To: pgsql-bugs(at)lists(dot)postgresql(dot)org, PostgreSQL-development <pgsql-hackers(at)postgresql(dot)org>
Subject: Negative cost is seen for plan node
Date: 2020-03-23 13:13:48
Message-ID: CAMbWs4_maqdBnRR4x01pDpoV-CiQ+RvMQaPm4JoTPbA=mZmhMw@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-bugs pgsql-hackers

Hi all,

With the following statements on latest master (c81bd3b9), I find
negative cost for plan nodes.

create table a (i int, j int);
insert into a select i%100000, i from generate_series(1,1000000)i;
analyze a;

# explain select i from a group by i;
QUERY PLAN
-----------------------------------------------------------------
HashAggregate (cost=1300.00..-1585.82 rows=102043 width=4)
Group Key: i
Planned Partitions: 4
-> Seq Scan on a (cost=0.00..14425.00 rows=1000000 width=4)
(4 rows)

In function cost_agg, when we add the disk costs of hash aggregation
that spills to disk, nbatches is calculated as 1.18 in this case. It is
greater than 1, so there will be spill. And the depth is calculated as
-1 in this case, with num_partitions being 4. I think this is where
thing goes wrong.

Thanks
Richard

Responses

Browse pgsql-bugs by date

  From Date Subject
Next Message PG Bug reporting form 2020-03-23 16:27:25 BUG #16311: Zero sized WAL archive logs on DAS
Previous Message Tom Lane 2020-03-23 04:20:51 Re: BUG #16304: ECPG won't accept input from STDIN

Browse pgsql-hackers by date

  From Date Subject
Next Message Laurenz Albe 2020-03-23 13:27:29 Re: Berserk Autovacuum (let's save next Mandrill)
Previous Message Pavel Stehule 2020-03-23 13:01:04 Re: is somewhere documented x LIKE ANY(ARRAY)?