Re: [HACKERS] Partition-wise aggregation/grouping
От | Jeevan Chalke |
---|---|
Тема | Re: [HACKERS] Partition-wise aggregation/grouping |
Дата | |
Msg-id | CAM2+6=WJYy69cqYE0wuUcb6MjK2R=YKB2cXGZtfisK0_zYiF-g@mail.gmail.com обсуждение исходный текст |
Ответ на | Re: [HACKERS] Partition-wise aggregation/grouping (David Rowley <david.rowley@2ndquadrant.com>) |
Ответы |
Re: [HACKERS] Partition-wise aggregation/grouping
(David Rowley <david.rowley@2ndquadrant.com>)
Re: [HACKERS] Partition-wise aggregation/grouping (Dilip Kumar <dilipbalaut@gmail.com>) |
Список | pgsql-hackers |
On Tue, Oct 10, 2017 at 1:31 PM, David Rowley <david.rowley@2ndquadrant.com> wrote:
I have tried exactly same tests to get to this factor on my local developer machine. And with parallelism enabled I got this number as 7.9. However, if I disable the parallelism (and I believe David too disabled that), I get this number as 1.8. Whereas for 10000 rows, I get this number to 1.7
-- With Gather
# select current_Setting('cpu_tuple_cost')::float8 / ((10633.56 * (81.035 / 72.450) - 10633.56) / 1000000);
7.9
-- Without Gather
# select current_Setting('cpu_tuple_cost')::float8 / ((16925.01 * (172.838 / 131.400) - 16925.01) / 1000000);
1.8
-- With 10000 rows (so no Gather too)
# select current_Setting('cpu_tuple_cost')::float8 / ((170.01 * (1.919 / 1.424) - 170.01) / 10000);
1.7
So it is not so straight forward to come up the correct heuristic here. Thus using 50% of cpu_tuple_cost look good to me here.
As suggested by Ashutosh and Robert, attached separate small WIP patch for it.
I think it will be better if we take this topic on another mail-thread.
Do you agree?
On 10 October 2017 at 17:57, Ashutosh Bapat
<ashutosh.bapat@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.
I have tried exactly same tests to get to this factor on my local developer machine. And with parallelism enabled I got this number as 7.9. However, if I disable the parallelism (and I believe David too disabled that), I get this number as 1.8. Whereas for 10000 rows, I get this number to 1.7
-- With Gather
# select current_Setting('cpu_tuple_cost')::float8 / ((10633.56 * (81.035 / 72.450) - 10633.56) / 1000000);
7.9
-- Without Gather
# select current_Setting('cpu_tuple_cost')::float8 / ((16925.01 * (172.838 / 131.400) - 16925.01) / 1000000);
1.8
-- With 10000 rows (so no Gather too)
# select current_Setting('cpu_tuple_cost')::float8 / ((170.01 * (1.919 / 1.424) - 170.01) / 10000);
1.7
So it is not so straight forward to come up the correct heuristic here. Thus using 50% of cpu_tuple_cost look good to me here.
As suggested by Ashutosh and Robert, attached separate small WIP patch for it.
I think it will be better if we take this topic on another mail-thread.
Do you agree?
--
David Rowley http://www.2ndQuadrant.com/
PostgreSQL Development, 24x7 Support, Training & Services
--
Jeevan Chalke
Technical Architect, Product Development
EnterpriseDB Corporation
The Enterprise PostgreSQL Company
Technical Architect, Product Development
EnterpriseDB Corporation
The Enterprise PostgreSQL Company
Вложения
В списке pgsql-hackers по дате отправления:
Предыдущее
От: Amit KapilaДата:
Сообщение: Re: [HACKERS] BLK_DONE state in XLogReadBufferForRedoExtended