From: | David Rowley <dgrowleyml(at)gmail(dot)com> |
---|---|
To: | Andy Fan <zhihui(dot)fan1213(at)gmail(dot)com> |
Cc: | Simon Riggs <simon(at)2ndquadrant(dot)com>, PostgreSQL Developers <pgsql-hackers(at)lists(dot)postgresql(dot)org> |
Subject: | Re: Hybrid Hash/Nested Loop joins and caching results from subplans |
Date: | 2020-06-29 23:57:03 |
Message-ID: | CAApHDvr-yx9DEJ1Lc9aAy8QZkgEZkTP=3hBRBe83Vwo=kAndcA@mail.gmail.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-hackers |
On Fri, 12 Jun 2020 at 16:10, Andy Fan <zhihui(dot)fan1213(at)gmail(dot)com> wrote:
> I first tried to see if we can have a row estimation before the subplan
> is created and it looks very complex. The subplan was created during
> preprocess_qual_conditions, at that time, we even didn't create the base
> RelOptInfo , to say nothing of join_rel which the rows estimation happens
> much later.
>
> Then I see if we can delay the cache decision until we have the rows estimation,
> ExecInitSubPlan may be a candidate. At this time we can't add a new
> ResutCache node, but we can add a cache function to SubPlan node with costed
> based. However the num_of_distinct values for parameterized variable can't be
> calculated which I still leave it as an open issue.
I don't really like the idea of stuffing this feature into some
existing node type. Doing so would seem pretty magical when looking
at an EXPLAIN ANALYZE. There is of course overhead to pulling tuples
through an additional node in the plan, but if you use that as an
argument then there's some room to argue that we should only have 1
executor node type to get rid of that overhead.
Tom mentioned in [1] that he's reconsidering his original thoughts on
leaving the AlternativeSubPlan selection decision until execution
time. If that were done late in planning, as Tom mentioned, then it
would be possible to give a more accurate cost to the Result Cache as
we'd have built the outer plan by that time and would be able to
estimate the number of distinct calls to the correlated subplan. As
that feature is today we'd be unable to delay making the decision
until execution time as we don't have the required details to know how
many distinct calls there will be to the Result Cache node.
For now, I'm planning on changing things around a little in the Result
Cache node to allow faster deletions from the cache. As of now, we
must perform 2 hash lookups to perform a single delete. This is
because we must perform the lookup to fetch the entry from the MRU
list key, then an additional lookup in the hash delete code. I plan
on changing the hash delete code to expose another function that
allows us to delete an item directly if we've already looked it up.
This should make a small reduction in the overheads of the node.
Perhaps if the overhead is very small (say < 1%) when the cache is of
no use then it might not be such a bad thing to just have a Result
Cache for correlated subplans regardless of estimates. With the TPCH
Q20 test, it appeared as if the overhead was 0.27% for that particular
subplan. A more simple subplan would execute more quickly resulting
the Result Cache overhead being a more significant portion of the
overall subquery execution. I'd need to perform a worst-case overhead
test to get an indication of what the percentage is.
David
[1] https://www.postgresql.org/message-id/1992952.1592785225@sss.pgh.pa.us
From | Date | Subject | |
---|---|---|---|
Next Message | Kyotaro Horiguchi | 2020-06-30 00:14:23 | Re: [Bug fix]There is the case archive_timeout parameter is ignored after recovery works. |
Previous Message | David Rowley | 2020-06-29 23:22:02 | Re: Open Item: Should non-text EXPLAIN always show properties? |