![]() | |
![]() |
| | Thread Tools | Display Modes |
#1
| |||
| |||
|
#2
| |||
| |||
|
|
I just noticed that JOINs with temporary tables are much slower than JOINs with base tables and like to ask if that is typical and what the technical cause is. Example: BEGIN SELECT DISTINCT t_at.vid_auftrag INTO #temp FROM t_at WHERE t_at.abgeschlossen_am > CAST('2009-01-01' AS DATE); SELECT DISTINCT t_atmk.vid_auftrag, t_atmk.vid_qmerkmal FROM t_at JOIN t_atmk JOIN t_hsp JOIN t_hm WHERE t_hm.picture_id_bild IS NOT NULL AND EXISTS (SELECT * FROM #temp WHERE #temp.vid_auftrag=t_at.vid_auftrag); END This simply fills a temporary table with PKs, and then uses these PKs to filter the second SELECT. On my lab machine, this needs 24 seconds. When not using the temporary table, but directly filtering the base table (it is joined anyways), this runs in 12 seconds -- 100% better performance: BEGIN SELECT DISTINCT t_atmk.vid_auftrag, t_atmk.vid_qmerkmal FROM t_at JOIN t_atmk JOIN t_hsp JOIN t_hm WHERE t_hm.picture_id_bild IS NOT NULL AND t_at.abgeschlossen_am CAST('2009-01-01' AS DATE); END Since the sole difference between both attempts is whether or not to buffer the intermediate PK list in a temporary table, I thought that the problem must be the creation of the temporary table. So I measured just the table creation: SELECT DISTINCT t_at.vid_auftrag INTO #temp FROM t_at WHERE t_at.abgeschlossen_am > CAST('2009-01-01' AS DATE); But actually, that just needs 0,016 seconds...! So in fact, the difference of 12 second is needed to JOIN with the intermediate result (which, BTW, contains just 567 PKs). I wonder why...!? Is there any technical explanation of this? Are JOINs with temporary tables (rember, it contains just 567 PKs) always so slow compared to JOINs with base tables? Regards Markus |
#3
| |||
| |||
|
|
Any news on this? I mean, anybody besides me interested in an answer why temp tables need 12 seconds more than base tables? "Markus KARG" <karg (AT) quipsy (DOT) de> schrieb im Newsbeitrag news:4a76bded$3 (AT) forums-3-dub (DOT) sybase.com... I just noticed that JOINs with temporary tables are much slower than JOINs with base tables and like to ask if that is typical and what the technical cause is. Example: BEGIN SELECT DISTINCT t_at.vid_auftrag INTO #temp FROM t_at WHERE t_at.abgeschlossen_am > CAST('2009-01-01' AS DATE); SELECT DISTINCT t_atmk.vid_auftrag, t_atmk.vid_qmerkmal FROM t_at JOIN t_atmk JOIN t_hsp JOIN t_hm WHERE t_hm.picture_id_bild IS NOT NULL AND EXISTS (SELECT * FROM #temp WHERE #temp.vid_auftrag=t_at.vid_auftrag); END This simply fills a temporary table with PKs, and then uses these PKs to filter the second SELECT. On my lab machine, this needs 24 seconds. When not using the temporary table, but directly filtering the base table (it is joined anyways), this runs in 12 seconds -- 100% better performance: BEGIN SELECT DISTINCT t_atmk.vid_auftrag, t_atmk.vid_qmerkmal FROM t_at JOIN t_atmk JOIN t_hsp JOIN t_hm WHERE t_hm.picture_id_bild IS NOT NULL AND t_at.abgeschlossen_am CAST('2009-01-01' AS DATE); END Since the sole difference between both attempts is whether or not to buffer the intermediate PK list in a temporary table, I thought that the problem must be the creation of the temporary table. So I measured just the table creation: SELECT DISTINCT t_at.vid_auftrag INTO #temp FROM t_at WHERE t_at.abgeschlossen_am > CAST('2009-01-01' AS DATE); But actually, that just needs 0,016 seconds...! So in fact, the difference of 12 second is needed to JOIN with the intermediate result (which, BTW, contains just 567 PKs). I wonder why...!? Is there any technical explanation of this? Are JOINs with temporary tables (rember, it contains just 567 PKs) always so slow compared to JOINs with base tables? Regards Markus |
![]() |
| Thread Tools | |
| Display Modes | |
| |