On 10 October 2017 at 17:57, Ashutosh Bapat <ashutosh.ba...@enterprisedb.com> wrote: > Append node just returns the result of ExecProcNode(). Charging > cpu_tuple_cost may make it too expensive. In other places where we > charge cpu_tuple_cost there's some processing done to the tuple like > ExecStoreTuple() in SeqNext(). May be we need some other measure for > Append's processing of the tuple.
I don't think there's any need to invent any new GUC. You could just divide cpu_tuple_cost by something. I did a quick benchmark on my laptop to see how much Append really costs, and with the standard costs the actual cost seems to be about cpu_tuple_cost / 2.4. So probably cpu_tuple_cost / 2 might be realistic. create_set_projection_path() does something similar and brincostestimate() does some similar magic and applies 0.1 * cpu_operator_cost to the total cost. # create table p (a int, b int); # create table p1 () inherits (p); # insert into p1 select generate_series(1,1000000); # vacuum analyze p1; # \q $ echo "select count(*) from p1;" > p1.sql $ echo "select count(*) from p;" > p.sql $ pgbench -T 60 -f p1.sql -n latency average = 58.567 ms $ pgbench -T 60 -f p.sql -n latency average = 72.984 ms $ psql psql (11devel) Type "help" for help. # -- check the cost of the plan. # explain select count(*) from p1; QUERY PLAN ------------------------------------------------------------------ Aggregate (cost=16925.00..16925.01 rows=1 width=8) -> Seq Scan on p1 (cost=0.00..14425.00 rows=1000000 width=0) (2 rows) # -- selecting from the parent is the same due to zero Append cost. # explain select count(*) from p; QUERY PLAN ------------------------------------------------------------------------ Aggregate (cost=16925.00..16925.01 rows=1 width=8) -> Append (cost=0.00..14425.00 rows=1000001 width=0) -> Seq Scan on p (cost=0.00..0.00 rows=1 width=0) -> Seq Scan on p1 (cost=0.00..14425.00 rows=1000000 width=0) (4 rows) # -- extrapolate the additional time taken for the Append scan and work out what the planner # -- should add to the plan's cost, then divide by the number of rows in p1 to work out the # -- tuple cost of pulling a row through the append. # select (16925.01 * (72.984 / 58.567) - 16925.01) / 1000000; ?column? ------------------------ 0.00416630302337493743 (1 row) # show cpu_tuple_cost; cpu_tuple_cost ---------------- 0.01 (1 row) # -- How does that compare to the cpu_tuple_cost? # select current_Setting('cpu_tuple_cost')::float8 / 0.00416630302337493743; ?column? ---------------- 2.400209476818 (1 row) Maybe it's worth trying with different row counts to see if the additional cost is consistent, but it's probably not worth being too critical here. -- David Rowley http://www.2ndQuadrant.com/ PostgreSQL Development, 24x7 Support, Training & Services -- Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-hackers