December 6, 2017 at 8:54 pm
have got a query(view) that needs to join multiple tables in a view. Currently have over 100 tables in the join - and this number could get larger. Does produce is a rather wide resultset (1 column per table)
joined tables are relatively small (c 6-8 columns) and with only c 120 rows each
join is simple one field key to one field key - and join target table IsLatest = 1
Performance is ok when joining upto c 75 tables - but then degrades quickly from that number upwards
any suggestions on how to improve perfomance ??
have been looking at HINTs / ParallelProcessing without much joy (yet)....
thx
m
December 7, 2017 at 7:15 am
Ideally, post the execution plan as a .sqlplan file. What kind of JOINs are we talking about? INNER ? OUTER ? APPLY? Are the tables indexed? What are the indexes? Please provide more details.
Steve (aka sgmunson) 🙂 🙂 🙂
Rent Servers for Income (picks and shovels strategy)
December 7, 2017 at 8:50 am
December 9, 2017 at 9:40 pm
Thx for the suggestions.
am on SQL 2016.
have got a working solution - and it appears to scale
Code was
SELECT
mainT. Column1
,SubT1.Column1 as c1
,SubT2.Column1 as c2
,SubT3.Column1 as c3
,SubT4.Column1 as c4
from MainTable mainT
inner join Subtable1 SubT1 on SubT1.key = mainT.key and SubT1.IsLatest = 1
inner join Subtable2 SubT2 on SubT2.key = mainT.key and SubT2.IsLatest = 1
inner join Subtable3 SubT3 on SubT3.key = mainT.key and SubT3.IsLatest = 1
inner join Subtable4 SubT4 on SubT4.key = mainT.key and SubT4.IsLatest = 1
Changed to be
SELECT
mainT.Column1
,(select Column1 from Subtable1 SubT1
where SubT1.key = mainT.key and SubT1.IsLatest = 1) c1
,(select Column1 from Subtable2 SubT2
where SubT2.key = mainT.key and SubT2.IsLatest = 1) c2
,(select Column1 from Subtable3 SubT3
where SubT3.key = mainT.key and SubT3.IsLatest = 1) c3
,(select Column1 from Subtable4 SubT4
where SubT4.key = mainT.key and SubT4.IsLatest = 1) c4
from MainTable mainT
did this for a query with over 100 tables - didn't get the performance degradation
so far, so good
December 9, 2017 at 10:34 pm
mark seidelin-407018 - Saturday, December 9, 2017 9:40 PMThx for the suggestions.
am on SQL 2016.have got a working solution - and it appears to scale
Code wasSELECT
mainT. Column1
,SubT1.Column1 as c1
,SubT2.Column1 as c2
,SubT3.Column1 as c3
,SubT4.Column1 as c4
from MainTable mainT
inner join Subtable1 SubT1 on SubT1.key = mainT.key and SubT1.IsLatest = 1
inner join Subtable2 SubT2 on SubT2.key = mainT.key and SubT2.IsLatest = 1
inner join Subtable3 SubT3 on SubT3.key = mainT.key and SubT3.IsLatest = 1
inner join Subtable4 SubT4 on SubT4.key = mainT.key and SubT4.IsLatest = 1Changed to be
SELECT
mainT.Column1
,(select Column1 from Subtable1 SubT1
where SubT1.key = mainT.key and SubT1.IsLatest = 1) c1
,(select Column1 from Subtable2 SubT2
where SubT2.key = mainT.key and SubT2.IsLatest = 1) c2
,(select Column1 from Subtable3 SubT3
where SubT3.key = mainT.key and SubT3.IsLatest = 1) c3
,(select Column1 from Subtable4 SubT4
where SubT4.key = mainT.key and SubT4.IsLatest = 1) c4
from MainTable mainTdid this for a query with over 100 tables - didn't get the performance degradation
so far, so good
The problem with the first query may be the fact that you've included an implicit WHERE clause in each join instead of in a separate real WHERE clause. Since your second query is a collection of multiple correlated subqueries, EVERYTHING is a part of a WHERE.
--Jeff Moden
Change is inevitable... Change for the better is not.
Viewing 5 posts - 1 through 4 (of 4 total)
You must be logged in to reply to this topic. Login to reply