473,722 Members | 2,295 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Performance problem with joins

1 New Member
Hi

i have a severe performance problem with one of my views which has 6 to 8 joins .. any help will be appreciated..
the view is:

CREATE OR REPLACE VIEW thsn.trade_view AS
SELECT tra.tra_id, tra.per_id, tra.fir_id, tra.tra_dcn, tra.tra_startda te::date AS tra_startdate, tra.tra_enddate ::date AS tra_enddate, tra.tra_highpri ce, tra.tra_lowpric e, tra.tra_shares, tra.tra_marketv alue, tra.tra_commons haresheld, tra.tra_directs haresheld, tra.tra_indirec tsharesheld, tra.fun_id, tra.tra_amended , tra.tra_ownersh ip, tra.tra_touchda te::date AS tra_touchdate, tra.tra_cdate, tra.tra_udate, tra.tra_relevan t, tra.tra_type, tra.tra_date::d ate AS tra_date,
per.per_fullnam e, fir.fir_name, fir.bra_id, cac90.pc_perf AS tra_performance 90, incac90.pc_perf AS tra_indexperfor mance90, cac180.pc_perf AS tra_performance 180, incac180.pc_per f AS tra_indexperfor mance180, cac270.pc_perf AS tra_performance 270, incac270.pc_per f AS tra_indexperfor mance270, kurl.kur_market cap AS tra_marketkap, kurl.kur_close AS tra_close, thsn.per_letzte bewertungkauf(p er.per_id, fir.fir_id) AS per_punktekauf, thsn.per_letzte bewertungverkau f(per.per_id, fir.fir_id) AS per_punkteverka uf, fun.fun_thid, fun.fun_name, wp.wp_symbol
FROM thsn.trade tra
JOIN thsn.person per ON tra.per_id = per.per_id
JOIN thsn.firma fir ON tra.fir_id = fir.fir_id
LEFT JOIN thsn.kurs_lates t kurl ON ('U'::text || fir.fir_cusip:: text) =kurl.fir_cusip
LEFT JOIN thsn.perfcache9 0 cac90 ON tra.tra_id = cac90.tra_id
LEFT JOIN thsn.indexperfc ache90 incac90 ON tra.tra_id = incac90.tra_id
LEFT JOIN thsn.perfcache1 80 cac180 ON tra.tra_id = cac180.tra_id
LEFT JOIN thsn.indexperfc ache180 incac180 ON tra.tra_id = incac180.tra_id
LEFT JOIN thsn.perfcache2 70 cac270 ON tra.tra_id = cac270.tra_id
LEFT JOIN thsn.indexperfc ache270 incac270 ON tra.tra_id = incac270.tra_id
LEFT JOIN thsn.funktion fun ON tra.fun_id = fun.fun_id
LEFT JOIN thsn.wertpapier wp ON fir.wp_id = wp.wp_id;


and now if i query this view with this explain query :

explain select * from thsn.trade_view tra where tra_date>'2006-05-29'

the output:

"Merge Right Join (cost=304605.98 ..319519.02 rows=324367 width=370)"
" Merge Cond: ("outer".wp_ id = "inner".wp_ id)"
" -> Index Scan using pk_wertpapier on wertpapier wp (cost=0.00..113 4.06 rows=30651 width=12)"
" -> Sort (cost=304605.98 ..305416.90 rows=324367 width=370)"
" Sort Key: fir.wp_id"
" -> Hash Left Join (cost=102943.82 ..274914.62 rows=324367 width=370)"
" Hash Cond: ("outer".fun _id = "inner".fun_id) "
" -> Hash Left Join (cost=102942.07 ..271019.38 rows=324367 width=340)"
" Hash Cond: ("outer".tra _id = "inner".tra_id) "
" -> Hash Left Join (cost=71679.05. .216585.25 rows=324367 width=308)"
" Hash Cond: ("outer".tra _id = "inner".tra_id) "
" -> Hash Left Join (cost=53148.50. .189791.47 rows=324367 width=297)"
" Hash Cond: ("outer".tra _id = "inner".tra_id) "
" -> Hash Left Join (cost=25994.49. .148209.39 rows=324367 width=275)"
" Hash Cond: (('U'::text || ("outer".fir_cu sip)::text) = ("inner".fir_cu sip)::text)"
" -> Hash Join (cost=24702.75. .133134.22 rows=324367 width=264)"
" Hash Cond: ("outer".per _id = "inner".per_id) "
" -> Hash Join (cost=1450.91.. 99340.45 rows=324367 width=237)"
" Hash Cond: ("outer".fir _id = "inner".fir_id) "
" -> Seq Scan on trade tra (cost=0.00..881 58.53 rows=324367 width=181)"
" Filter: ((tra_date)::da te > '2006-05-29'::date)"

"-> Hash (cost=1374.53.. 1374.53 rows=30553 width=56)"
"-> Seq Scan on firma fir (cost=0.00..137 4.53 rows=30553 width=56)"
"-> Hash (cost=22629.87. .22629.87 rows=248787 width=27)"
"-> Seq Scan on person per (cost=0.00..226 29.87 rows=248787 width=27)"
"-> Hash (cost=1232.59.. 1232.59 rows=23659 width=35)"
"-> Seq Scan on kurs_latest kurl (cost=0.00..123 2.59 rows=23659 width=35)"
"-> Hash (cost=17244.44. .17244.44 rows=814044 width=19)"
"-> Seq Scan on perfcache90 cac90 (cost=0.00..172 44.44 rows=814044 width=19)"
" -> Hash (cost=6994.97.. 6994.97 rows=351797 width=19)"
" -> Seq Scan on indexperfcache9 0 incac90 (cost=0.00..699 4.97 rows=351797 width=19)"
" -> Hash (cost=16590.44. .16590.44 rows=776044 width=19)"
" -> Seq Scan on perfcache180 cac180 (cost=0.00..165 90.44 rows=776044 width=19)"
" -> Hash (cost=6704.00.. 6704.00 rows=336800 width=18)"
" -> Seq Scan on indexperfcache1 80 incac180 (cost=0.00..670 4.00 rows=336800 width=18)"
" -> Hash (cost=14755.09. .14755.09 rows=695309 width=19)"
" -> Seq Scan on perfcache270 cac270 (cost=0.00..147 55.09 rows=695309 width=19)"
" -> Hash (cost=6413.93.. 6413.93 rows=323893 width=19)"
" -> Seq Scan on indexperfcache2 70 incac270 (cost=0.00..641 3.93 rows=323893 width=19)"
" -> Hash (cost=1.60..1.6 0 rows=60 width=34)"
" -> Seq Scan on funktion fun (cost=0.00..1.6 0 rows=60 width=34)"


and without the joins if i run a explain on this query:

EXPLAIN SELECT tra.tra_id, tra.per_id, tra.fir_id, tra.tra_dcn, tra.tra_startda te::date AS tra_startdate, tra.tra_enddate ::date AS tra_enddate, tra.tra_highpri ce, tra.tra_lowpric e, tra.tra_shares, tra.tra_marketv alue, tra.tra_commons haresheld, tra.tra_directs haresheld, tra.tra_indirec tsharesheld, tra.fun_id, tra.tra_amended , tra.tra_ownersh ip, tra.tra_touchda te::date AS tra_touchdate, tra.tra_cdate, tra.tra_udate, tra.tra_relevan t, tra.tra_type, tra.tra_date::d ate AS tra_date, per.per_fullnam e, fir.fir_name, fir.bra_id, cac90.pc_perf AS tra_performance 90, incac90.pc_perf AS tra_indexperfor mance90, cac180.pc_perf AS tra_performance 180, incac180.pc_per f AS tra_indexperfor mance180, cac270.pc_perf AS tra_performance 270, incac270.pc_per f AS tra_indexperfor mance270, kurl.kur_market cap AS tra_marketkap, kurl.kur_close AS tra_close,
thsn.per_letzte bewertungkauf(p er.per_id, fir.fir_id) AS per_punktekauf, thsn.per_letzte bewertungverkau f(per.per_id, fir.fir_id) AS per_punkteverka uf, fun.fun_thid, fun.fun_name, wp.wp_symbol

FROM thsn.trade tra , thsn.person per, thsn.firma fir,thsn.kurs_l atest kurl , thsn.perfcache9 0 cac90, thsn.indexperfc ache90 incac90 , thsn.perfcache1 80 cac180 ,thsn.indexperf cache180 incac180 ,thsn.perfcache 270 cac270, thsn.indexperfc ache270 incac270 , thsn.funktion fun, thsn.wertpapier wp

where tra_date>'2006-06-30' and tra.per_id = per.per_id and tra.fir_id = fir.fir_id and ('U'::text || fir.fir_cusip:: text) = kurl.fir_cusip: :text and tra.tra_id = cac90.tra_id and tra.tra_id = incac90.tra_id and tra.tra_id = cac180.tra_id and tra.tra_id = incac180.tra_id and tra.tra_id = cac270.tra_id and tra.tra_id = incac270.tra_id and tra.fun_id = fun.fun_id and fir.wp_id = wp.wp_id

the output:

"Nested Loop (cost=64179.28. .90645.20 rows=394 width=370)"
" -> Nested Loop (cost=64179.28. .89072.83 rows=394 width=343)"
" -> Nested Loop (cost=64179.28. .87183.66 rows=471 width=372)"
" -> Nested Loop (cost=64179.28. .81962.24 rows=1304 width=353)"
" -> Nested Loop (cost=64179.28. .74632.57 rows=1825 width=334)"
" -> Merge Join (cost=64179.28. .65424.31 rows=2289 width=315)"
" Merge Cond: ("outer".wp_ id = "inner".wp_ id)"
" -> Index Scan using pk_wertpapier on wertpapier wp (cost=0.00..113 4.06 rows=30651 width=12)"
" -> Sort (cost=64179.28. .64185.15 rows=2349 width=315)"
" Sort Key: fir.wp_id"
" -> Seq Scan on indexperfcache1 80 incac180 (cost=0.00..670 4.00 rows=336800 width=18)"
" -> Hash (cost=54717.99. .54717.99 rows=9690 width=267)"
" -> Merge Join (cost=42275.34. .54717.99 rows=9690 width=267)"
" Merge Cond: ("outer".tra _id = "inner".tra_id) "
" -> Index Scan using pk_indexperfcac he270 on indexperfcache2 70 incac270 (cost=0.00..113 93.83 rows=323893 width=19)"
" -> Sort (cost=42275.34. .42348.12 rows=29114 width=248)"
" Sort Key: tra.tra_id"
" -> Hash Join (cost=4224.87.. 40116.62 rows=29114 width=248)"
" Hash Cond: ("outer".fir _id = "inner".fir_id) "
" -> Bitmap Heap Scan on trade tra (cost=183.96..3 5201.91 rows=29133 width=181)"
" Recheck Cond: (tra_date > '2006-06-30 00:00:00'::time stamp without time zone)"
" -> Bitmap Index Scan on trade_date_inde x (cost=0.00..183 .96 rows=29133 width=0)"
" Index Cond: (tra_date > '2006-06-30 00:00:00'::time stamp without time zone)"

" -> Hash (cost=3964.57.. 3964.57 rows=30533 width=67)"
" -> Hash Join (cost=1291.74.. 3964.57 rows=30533 width=67)"
" Hash Cond: (('U'::text || ("outer".fir_cu sip)::text) = ("inner".fir_cu sip)::text)"
" -> Seq Scan on firma fir (cost=0.00..137 4.53 rows=30553 width=56)"
" -> Hash (cost=1232.59.. 1232.59 rows=23659 width=35)"
" -> Seq Scan on kurs_latest kurl (cost=0.00..123 2.59 rows=23659 width=35)"
" -> Hash (cost=1.60..1.6 0 rows=60 width=34)"
"-> Seq Scan on funktion fun (cost=0.00..1.6 0 rows=60 width=34)"
"-> Index Scan using pk_perfcache180 on perfcache180 cac180 (cost=0.00..4.0 1 rows=1 width=19)"
" Index Cond: ("outer".tra _id = cac180.tra_id)"
"-> Index Scan using pk_perfcache270 on perfcache270 cac270 (cost=0.00..4.0 0 rows=1 width=19)"
" Index Cond: ("outer".tra _id = cac270.tra_id)"
"-> Index Scan using pk_indexperfcac he90 on indexperfcache9 0 incac90 (cost=0.00..3.9 9 rows=1 width=19)"
"Index Cond: ("outer".tra _id = incac90.tra_id) "
" -> Index Scan using pk_perfcache90 on perfcache90 cac90 (cost=0.00..4.0 0 rows=1 width=19)"
" Index Cond: ("outer".tra _id = cac90.tra_id)"
"-> Index Scan using pk_person on person per (cost=0.00..3.9 6 rows=1 width=27)"
" Index Cond: ("outer".per _id = per.per_id)"


In this case the time taken is much less and also the index in the tra_date cloumn is considered while with the view the index is not considered and also other indexes are not considered.

What is it that i am doing wrong?

Thanks in advance.
Sep 8 '06 #1
1 3112
PEB
1,418 Recognized Expert Top Contributor
The things that impression me are:

LEFT JOIN thsn.kurs_lates t kurl ON ('U'::text || fir.fir_cusip:: text) =kurl.fir_cusip

U concatenate string in a join... Try to do it without concatenation.. .

U also use a multiple Left Joins...

The Left Join isn't as the Inner Join... It is slower...

Try to minimize the use of Left joins..

:)
Sep 23 '06 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

0
2528
by: Jaz | last post by:
Hello, Could do with a bit of advice regarding left joins, would be much appreciated! OK, I have a table of products. I wish to have another table of images (filenames only) and a third table which links products to images (i.e: productID | imageID only). So... if I do a select like this:
1
1921
by: tekanet | last post by:
Hello folks, first of all I really don't know how you gurus call this way of writing joins: SELECT A.FIELD, B.FIELD FROM TABLE_A A, TABLE_B B
4
10935
by: GM | last post by:
Does the order in which Joins are peformed (from left to right) matter whether inner or outer when it comes to performance. Assuming that all indexes are the same but the size of the tables is different? For example let's assume we have 5 tables, TABLE1, TABLE2, TABLE3, TABLE4, TABLE5. For example: SELECT Smth from TABLE1 INNER JOIN TABLE2 on Condition1 INNER JOIN TABLE3 on Condition2
3
1635
by: Not Me | last post by:
Hi, Can't post specifics at the moment but if this seems like a common problem any help would be appreciated. When querying with ~6 tables, using mostly left outer joins, I get standard performance with the where clause where XXX is not null
1
3515
by: Andreas Lauffer | last post by:
I changed from Access97 to AccessXP and I have immense performance problems. Details: - Access XP MDB with Jet 4.0 ( no ADP-Project ) - Linked Tables to SQL-Server 2000 over ODBC I used the SQL Profile to watch the T-SQL-Command which Access ( who creates the commands?) creates and noticed:
5
4003
by: Scott | last post by:
I have a customer that had developed an Access97 application to track their business information. The application grew significantly and they used the Upsizing Wizard to move the tables to SQL 2000. Of course there were no modifications made to the queries and they noticed significant performance issues. They recently upgraded the application to Access XP expecting the newer version to provide performance benefits and now queries take...
3
1582
by: MikeH | last post by:
I have the weirdest problem with an Access 97 database... The application comprises the usual front-back split database. It's built around Access 97 and had been running without serious problems for around seven years. The back-ends are replicated across two servers (althugh I don't think this is a replication problem). Around two weeks ago users suddenly started to complain about slow performance. One particular operation that used...
4
1777
by: Bob Alston | last post by:
Some more, rather specific Access performance questions. IN a split front-end & back-end Access/Jet ONLY LAN situation, and with all query criteria fields and join fields indexed: 1. Is is good form to have a single query with base table with criteria joined to a related table - all in one query? Or should I do a two-step, first query does selection of main table and then join with other table? 2. I have a table with multiple...
3
1919
by: Hadley Willan | last post by:
Hi all, I am using some views now to put together a particular format for my Java client factory to produce Java Beans from the database. Because we support internationalisation we are representing values as an id then storing their multiple languages in unicode to support the same repesentation at the database. This format is:
0
8863
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8739
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9384
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
9157
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
1
6681
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4502
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4762
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
2602
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2147
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.