Re: Making JIT more granular

From: Andy Fan <zhihui(dot)fan1213(at)gmail(dot)com>
To: David Rowley <dgrowleyml(at)gmail(dot)com>
Cc: PostgreSQL Developers <pgsql-hackers(at)lists(dot)postgresql(dot)org>, Andres Freund <andres(at)anarazel(dot)de>, Magnus Hagander <magnus(at)hagander(dot)net>
Subject: Re: Making JIT more granular
Date: 2022-05-16 00:06:07
Message-ID: CAKU4AWquQf1rYymcxCLB+npV1QinZJNm5Zdh5vmcArGh3DZxqA@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

>
>
> 2. You calculate the cost to compare with jit_above_cost as:
>
> plan->total_cost * plan->est_loops.
>
> An alternative way might be to consider the rescan cost like
> cost_rescan. This should be closer for a final execution cost.
> However since it is hard to set a reasonable jit_above_cost,
> so I am feeling the current way is OK as well.
>

There are two observers after thinking more about this. a). due to the
rescan cost reason, plan->total_cost * plan->est_loops might be greater
than the whole plan's total_cost. This may cause users to be confused why
this change can make the plan not JITed in the past, but JITed now.

explain analyze select * from t1, t2 where t1.a = t2.a;
QUERY PLAN

------------------------------------------------------------------------------------------------------------
Nested Loop (cost=0.00..154.25 rows=100 width=16) (actual
time=0.036..2.618 rows=100 loops=1) Join Filter: (t1.a = t2.a) Rows
Removed by Join Filter: 9900 -> Seq Scan on t1 (cost=0.00..2.00
rows=100 width=8) (actual time=0.015..0.031 rows=100 loops=1) ->
Materialize (cost=0.00..2.50 rows=100 width=8) (actual time=0.000..0.010
rows=100 loops=100) -> Seq Scan on t2 (cost=0.00..2.00 rows=100
width=8) (actual time=0.007..0.023 rows=100 loops=1) Planning Time: 0.299
ms Execution Time: 2.694 ms (8 rows)

The overall plan's total_cost is 154.25, but the Materialize's JIT cost is
2.5 * 100 = 250.

b). Since the total_cost for a plan counts all the costs for its children,
so if one
child plan is JITed, I think all its parents would JITed. Is this by
design?

QUERY PLAN
----------------------------
Sort
Sort Key: (count(*))
-> HashAggregate
Group Key: a
-> Seq Scan on t1

(If Seq Scan is JITed, both HashAggregate & Sort will be JITed.)

--
Best Regards
Andy Fan

In response to

Browse pgsql-hackers by date

  From Date Subject
Next Message osumi.takamichi@fujitsu.com 2022-05-16 00:58:46 RE: First draft of the PG 15 release notes
Previous Message Tatsuo Ishii 2022-05-15 23:46:10 Re: gitmaster access