performance - Multiples INNER JOIN is too slow SQL SERVER -


i'm having performance problem.

i created table receives data file, bulk insert. select multiple inner joins (11 inner joins) insert table right data.

when run select, takes long (more hour) , stop it. solution break query 3, creating @temp tables. surprise, takes 3 minutes. that's i'm trying understand, why breaking query 3 faster 1 select statement. here query:

select t1.returnint, t1.returnbit, t2.returnint, t3.returnint, t5.returnint, t1.returndatetime t1 inner join t2     on t2.my_column_varchar = t1.my_column_varchar inner join t3     on t3.my_column_number = t1.my_column_number , t2.my_column_id = t3.my_column_id inner join t4     on t4.my_column_varchar = t1.my_column_varchar inner join t5     on t5.my_column_int = t1.my_column_int , t5.my_column_int = t4.my_column_int , t2.my_column_int = t5.my_column_int inner join t6     on t6.my_column_int = t5.my_column_int , t6.my_column_int = t2.my_column_int inner join t7     on t7.my_column_int = t6.my_column_int inner join t8     on t8.my_column_int = t3.my_column_int , t8.my_column_datetime = t1.my_column_datetime inner join t9     on t9.my_column_int = t3.my_column_int , t8.my_column_datetime between t9.my_column_datetime1 , t9.datetime1 + t9.my_column_datetime2 inner join t10     on t10.my_column_int = t9.my_column_int , t10.my_column_int = t6.my_column_int inner join t11     on t11.my_column_int = t9.my_column_int , t8.my_column_datetime = t11.my_column_datetime 

----edited----

there no clause, query put here.

here broken querys, forget put them here. runs in 3 minutes.

declare @temp table (     <some_columns> ) insert @temp     select <my_linked_columns>     t1     inner join t2         on t2.my_column_varchar = t1.my_column_varchar     inner join t3         on t3.my_column_number = t1.my_column_number , t2.my_column_id = t3.my_column_id     inner join t4         on t4.my_column_varchar = t1.my_column_varchar     inner join t5         on t5.my_column_int = t1.my_column_int , t5.my_column_int = t4.my_column_int , t2.my_column_int = t5.my_column_int   declare @temp2 table(     <some_columns> ) insert @temp2     select <more_linked_columns>     @temp temp     inner join t6         on t6.my_column_int = temp.my_column_int , t6.my_column_int = temp.my_column_int     inner join t7         on t7.my_column_int = t6.my_column_int     inner join t8         on t8.my_column_int = temp.my_column_int , t8.my_column_datetime = temp.my_column_datetime   declare @temp3 table(     <some_columns> ) insert @temp3     select <more_linked_columns>     @temp2 temp2     inner join t9         on t9.my_column_int = temp2.my_column_int , temp2.my_column_datetime between t9.my_column_datetime1 , t9.datetime1 + t9.my_column_datetime2     inner join t10         on t10.my_column_int = t9.my_column_int , t10.my_column_int = temp2.my_column_int     inner join t11         on t11.my_column_int = t9.my_column_int , temp2.my_column_datetime = t11.my_column_datetime   select <all_final_columns> @temp3 

----edited 3----

studying more things discovered problem in execution plan. have nested loop estimates 1 row returns 1.204.014 rows. guess problem here, didn't find out how solve problem without breaking query in 3 parts (now know why breaking faster hehehe)

most common reasons:

reason 1: when 2 tables having n , m rows participating in inner join have many many relationship, inner join can near cross join , can produce result set more max(n,m) rows, theoretically n x m rows possible.

now imagine many such tables in inner join.

this result in result set becoming bigger , bigger , start eating allocated memory area.

this reason why temp tables might you.

reason 2: not have index built on columns joining tables on.

reason 3: have functions in where clause?


Comments

Popular posts from this blog

yii2 - Yii 2 Running a Cron in the basic template -

asp.net - 'System.Web.HttpContext' does not contain a definition for 'GetOwinContext' Mystery -

mercurial graft feature, can it copy? -