pg.ddx.io pgsql-performance@postgresql.org mailing list archive
help / color / mirror / Atom feedCorrecting Hash Join Estimates
3+ messages / 3 participants
[nested] [flat]
* Correcting Hash Join Estimates
@ 2005-04-04 05:08 mark.lubratt@indeq.com
0 siblings, 1 reply; 3+ messages in thread
From: mark.lubratt@indeq.com @ 2005-04-04 05:08 UTC (permalink / raw)
To: pgsql-performance
Hello!
I posted a similar question to this one about a month ago; but, for some
reason, it never seemed to be broadcast eventhough it ended up in the
archives. So, since I'm still struggling with this, I thought I'd
repost...
I'm trying to optimize a query and the EXPLAIN ANALYZE (see link below)
shows that some hash join row estimates are wrong by a factor of 2-3,
and upwards of 7-8. There is a corresponding mis-estimation of the
amount of time taken for these steps. The database is vacuum analyzed
nightly by a cron job. How would I go about tightening up these
errors? I suspect that I need to SET STATISTIC on some columns, but
how can I tell which columns?
Any help would be appreciated.
WinXP (dual Xeon 1.2GB RAM) PgSQL 8.0.1
Explain Analyze: <http://www.indeq.com/EA.txt;
View Definition: <http://www.indeq.com/VGAUA.txt;
The largest table contains about 10,000 rows. All tables have indexes
on their foreign keys.
Thanks!
Mark
^ permalink raw reply [nested|flat] 3+ messages in thread
* Re: Correcting Hash Join Estimates
@ 2005-04-04 05:54 Tom Lane <tgl@sss.pgh.pa.us>
parent: mark.lubratt@indeq.com
0 siblings, 1 reply; 3+ messages in thread
From: Tom Lane @ 2005-04-04 05:54 UTC (permalink / raw)
To: mark.lubratt@indeq.com; +Cc: pgsql-performance
mark.lubratt@indeq.com writes:
> I'm trying to optimize a query and the EXPLAIN ANALYZE (see link below)
> shows that some hash join row estimates are wrong by a factor of 2-3,
> and upwards of 7-8.
I doubt that improving those estimates would lead to markedly better
results. You need to think about improving the view design instead.
What context is this view used in --- do you just do "select * from
view_get_all_user_award2", or are there conditions added to it, or
perhaps it gets joined with other things? Do you really need the
DISTINCT constraint? Do you really need the ORDER BY? Can you
simplify the WHERE clause at all?
Half a second sounds pretty decent to me for a ten-way join with a WHERE
clause as unstructured as that. If you really need it to execute in way
less time, you're probably going to have to rethink your data
representation to make the query simpler.
regards, tom lane
^ permalink raw reply [nested|flat] 3+ messages in thread
* Re: Correcting Hash Join Estimates
@ 2005-04-04 06:15 Mark Lubratt <mark.lubratt@indeq.com>
parent: Tom Lane <tgl@sss.pgh.pa.us>
0 siblings, 0 replies; 3+ messages in thread
From: Mark Lubratt @ 2005-04-04 06:15 UTC (permalink / raw)
To: pgsql-performance
On Apr 4, 2005, at 12:54 AM, Tom Lane wrote:
> mark.lubratt@indeq.com writes:
>> I'm trying to optimize a query and the EXPLAIN ANALYZE (see link
>> below)
>> shows that some hash join row estimates are wrong by a factor of 2-3,
>> and upwards of 7-8.
>
> I doubt that improving those estimates would lead to markedly better
> results. You need to think about improving the view design instead.
> What context is this view used in --- do you just do "select * from
> view_get_all_user_award2", or are there conditions added to it, or
> perhaps it gets joined with other things?
Yes. I forgot to show how the query is executed...
select * from view_get_all_user_award2 where person_id = 1;
> Do you really need the
> DISTINCT constraint?
Yes.
> Do you really need the ORDER BY?
The customer wants an initial ordering in the displayed data.
> Can you
> simplify the WHERE clause at all?
>
I originally had a bunch of LEFT JOINs. After reading Tow's "SQL
Tuning", I was hoping to steer the planner into a more "optimal" plan
by using a large where clause instead and doing the joins there (I
think they're called implicit joins). I was able to shave a couple of
hundred milliseconds off the execution time by doing this.
> Half a second sounds pretty decent to me for a ten-way join with a
> WHERE
> clause as unstructured as that. If you really need it to execute in
> way
> less time, you're probably going to have to rethink your data
> representation to make the query simpler.
>
Unfortunately, I'm not sure I can restructure the data. I did consider
materialized views. However, they couldn't be lazy and that seemed
like a lot of extra work for the backend for very little improvement.
If this sounds like decent performance to you... I guess I can just
tell the complainers that it's as good as it's going to get (barring a
major hardware upgrade...).
Thanks!
Mark
^ permalink raw reply [nested|flat] 3+ messages in thread
end of thread, other threads:[~2005-04-04 06:15 UTC | newest]
Thread overview: 3+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2005-04-04 05:08 Correcting Hash Join Estimates mark.lubratt@indeq.com
2005-04-04 05:54 ` Tom Lane <tgl@sss.pgh.pa.us>
2005-04-04 06:15 ` Mark Lubratt <mark.lubratt@indeq.com>
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox