February 9, 2023 at 7:59 pm
Data which is distributed over multiple databases needs to be gathered and then queried/filtered.
Currenttly a temporary table in which the records are inserted from the different databases is used however it
is really slow, is there a faster way to handle it?
February 9, 2023 at 9:02 pm
If all the databases are on the same instance, why do you need to use a temporary table?
Also, does your temporary table actually have the correct indexes on it?
--Jeff Moden
Change is inevitable... Change for the better is not.
February 9, 2023 at 9:07 pm
I guess you mean selecting them with union all, that's even worse performance wise.
It does.
February 9, 2023 at 9:17 pm
oh god no don't use UNION ALL unless you really need to.
Why not just something like this to get all the records you need from each source?
INSERT INTO tempdb.TableName(col1, col2, col3)
SELECT colA, colB, colC
FROM SomeDb.schemaA.T1
WHERE x=1;
Or
INSERT INTO tempdb.TableName
EXEC db.schema.StoredProcedureName @param1=1...
and then if the table in tempdb is indexed, you should be ready to go, right?
February 10, 2023 at 12:31 am
I guess you mean selecting them with union all, that's even worse performance wise.
It does.
No... and no where did I come close to even inferring that. I mean use the tables like normal tables by adding synonyms in the "current" database to the tables in those other databases so that you can also follow the "2 part naming convention". You might even want to consider a "Partitioned View" if all the databases are on the same instance (they can be "distributed" to other instances but that's both a pain and a risk).
Also, you've given us practically zero information for use to help you with performance. Please see the article at the 2nd link in my signature line below for how to seriously increase your chances of getting help for performance issues.
--Jeff Moden
Change is inevitable... Change for the better is not.
February 10, 2023 at 3:38 am
As I said second option is still used but it's slow. @pietlinden
@jeff Moden: which requires a union all? 😅 , No thx
February 10, 2023 at 5:43 am
As I said second option is still used but it's slow. @pietlinden
@jeff Moden: which requires a union all? 😅 , No thx
As opposed to what??? The (in your own words) SLOW Temp Table you currently have? Contrary to what's been stated, UNION ALL , especially when properly used in Partitioned Views, doesn't slow anything down. What slows things down is the code that queries against it.
But, you seem like you know it all. Do what you think you need to. 😉
p.s. It's actually UNION and not UNION ALL that has the performance issue because it has a built in form of DISTINCT. Other than a post on this thread, I'm not sure where you came up with the incorrect notion that UNION ALL is slow when used PROPERLY. 😉
To be sure, though, you haven't posted anything of particular use for us to actually help you with your performance issue. You might not need your SLOW TEMP table (and it shouldn't be slow but we have no info on that or your code) and you might not need UNION ALL (again, no way for us to know)
--Jeff Moden
Change is inevitable... Change for the better is not.
February 10, 2023 at 5:50 am
oh god no don't use UNION ALL unless you really need to. Why not just something like this to get all the records you need from each source?
INSERT INTO tempdb.TableName(col1, col2, col3) SELECT colA, colB, colC FROM SomeDb.schemaA.T1 WHERE x=1;
Or INSERT INTO tempdb.TableName EXEC db.schema.StoredProcedureName @param1=1...
and then if the table in tempdb is indexed, you should be ready to go, right?
Why do YOU think UNION ALL is a sin of some sort here? Done correctly, it can be used to make a VERY high speed minimally logged insert into a Temp Table. And, used in a properly constructed Partitioned View, it will eliminate the need for the Temp Table altogether.
--Jeff Moden
Change is inevitable... Change for the better is not.
February 10, 2023 at 7:44 am
This was removed by the editor as SPAM
February 13, 2023 at 3:02 pm
Data which is distributed over multiple databases needs to be gathered and then queried/filtered.
Are these databases on the same instance, or different instances or servers?
Currenttly a temporary table in which the records are inserted from the different databases is used however it
What method are you using to gather this data, and put it into a temp table?
is really slow, is there a faster way to handle it?
WHAT is slow? Loading the temp table, or querying the temp table?
Michael L John
If you assassinate a DBA, would you pull a trigger?
To properly post on a forum:
http://www.sqlservercentral.com/articles/61537/
February 13, 2023 at 3:03 pm
Data which is distributed over multiple databases needs to be gathered and then queried/filtered.
Are these databases on the same instance, or different instances or servers?
Currenttly a temporary table in which the records are inserted from the different databases is used however it
What method are you using to gather this data, and put it into a temp table?
is really slow, is there a faster way to handle it?
WHAT is slow? Loading the temp table, or querying the temp table?
Michael L John
If you assassinate a DBA, would you pull a trigger?
To properly post on a forum:
http://www.sqlservercentral.com/articles/61537/
Viewing 11 posts - 1 through 10 (of 10 total)
You must be logged in to reply to this topic. Login to reply