November 5, 2018 at 4:10 am
I have around 200 tables and we have insert in each table with in each seconds.
so there are around 90 million records in all tables. We want to execute an SP against each row in a table. Trigger is not a choice for us because it will further slow down things. I am making a custom solution to loop over a every row in a table and execute SP in a loop.
How can i make this in parallel by using SQL or SSIS package. I am using MSSQL Server 2016.
Please advice me for better solution.
November 5, 2018 at 5:32 am
azhar.iqbal499 - Monday, November 5, 2018 4:10 AMI have around 200 tables and we have insert in each table with in each seconds.
so there are around 90 million records in all tables. We want to execute an SP against each row in a table. Trigger is not a choice for us because it will further slow down things. I am making a custom solution to loop over a every row in a table and execute SP in a loop.
How can i make this in parallel by using SQL or SSIS package. I am using MSSQL Server 2016.
Please advice me for better solution.
You want to execute a stored procedure for every row in every table of your database? Can you describe the reason, please?
The absence of evidence is not evidence of absence
- Martin Rees
The absence of consumable DDL, sample data and desired results is, however, evidence of the absence of my response
- Phil Parkin
November 5, 2018 at 5:44 am
azhar.iqbal499 - Monday, November 5, 2018 4:10 AMI have around 200 tables and we have insert in each table with in each seconds.
so there are around 90 million records in all tables. We want to execute an SP against each row in a table. Trigger is not a choice for us because it will further slow down things. I am making a custom solution to loop over a every row in a table and execute SP in a loop.
How can i make this in parallel by using SQL or SSIS package. I am using MSSQL Server 2016.
Please advice me for better solution.
Can you transform the SP into a function and call it from a CROSS APPLY?
November 5, 2018 at 6:01 am
azhar.iqbal499 - Monday, November 5, 2018 4:10 AMI have around 200 tables and we have insert in each table with in each seconds.
so there are around 90 million records in all tables. We want to execute an SP against each row in a table. Trigger is not a choice for us because it will further slow down things. I am making a custom solution to loop over a every row in a table and execute SP in a loop.
How can i make this in parallel by using SQL or SSIS package. I am using MSSQL Server 2016.
Please advice me for better solution.
How long do you have and how often will you need to do such a thing? Executing a stored procedure 90 million times, even in parallel, is going to use a whole lot of resources and take a long time. If you can (and you should if this is going to happen again), rewrite the stored procedure so that it's not RBAR in nature. "Stop thinking about what you want to do to a row... instead, think about what you want to do to a column".
--Jeff Moden
Change is inevitable... Change for the better is not.
November 6, 2018 at 1:50 am
It is the business requirement to call the SPs against each Row. I am thinking to Call After trigger on each row insert and implement Service Broker Queue to call Sps. This will provides me parallel and asynchronous execution of SP. Or can I use SSIS for parallel processing.
Please suggest.
November 6, 2018 at 2:52 am
azhar.iqbal499 - Tuesday, November 6, 2018 1:50 AMIt is the business requirement to call the SPs against each Row. I am thinking to Call After trigger on each row insert and implement Service Broker Queue to call Sps. This will provides me parallel and asynchronous execution of SP. Or can I use SSIS for parallel processing.
Please suggest.
What will the stored procedure (or whatever) actually do?
When should it execute?
For fast, accurate and documented assistance in answering your questions, please read this article.
Understanding and using APPLY, (I) and (II) Paul White
Hidden RBAR: Triangular Joins / The "Numbers" or "Tally" Table: What it is and how it replaces a loop Jeff Moden
November 6, 2018 at 6:52 am
azhar.iqbal499 - Tuesday, November 6, 2018 1:50 AMIt is the business requirement to call the SPs against each Row. I am thinking to Call After trigger on each row insert and implement Service Broker Queue to call Sps. This will provides me parallel and asynchronous execution of SP. Or can I use SSIS for parallel processing.
Please suggest.
There is a business requirement. It may or may not be satisfied by calling an SP against 90 million rows individually, but that is a technical solution to the business requirement, not the requirement itself. As Jeff said, if you think about what you want to do to a column, there may be a better way, but we won't know unless you give us the underlying requirement.
November 7, 2018 at 1:46 am
Actually I am working over Drilling Software which insert 1 row a into a table after five second. We Pass Some columns as parameter to a SP for Each row. These sps are called after every insert and it should not impact the OLTP. These SP are used to build some R Model so they needs Parameters for each row.
Client suggest me implement Service Broker for this. But for me it is extra overhead to manage Service Queue for just calling Procedure.
So What I did, on every insert of Row, I add same row in Audit table through after trigger. Trigger is only for INSERT. Then Loop on this table to call sp and mark the Flag isExecuted=TRUE, so that i don't pick record next time.
I can create multiple SPs to run them parallel on the basis of ID identity column in the Audit table. I will move this stuff into a job and job will run continuously to cater new records in a base table.
is that make sense?
Any better idea would be highly appreciated.
Thanks in Advance.
November 7, 2018 at 1:54 am
azhar.iqbal499 - Wednesday, November 7, 2018 1:46 AMActually I am working over Drilling Software which insert 1 row a into a table after five second. We Pass Some columns as parameter to a SP for Each row. These sps are called after every insert and it should not impact the OLTP. These SP are used to build some R Model so they needs Parameters for each row.
Client suggest me implement Service Broker for this. But for me it is extra overhead to manage Service Queue for just calling Procedure.
So What I did, on every insert of Row, I add same row in Audit table through after trigger. Trigger is only for INSERT. Then Loop on this table to call sp and mark the Flag isExecuted=TRUE, so that i don't pick record next time.
I can create multiple SPs to run them parallel on the basis of ID identity column in the Audit table. I will move this stuff into a job and job will run continuously to cater new records in a base table.
is that make sense?
Any better idea would be highly appreciated.Thanks in Advance.
Have you considered some form of replication for this? The impact on your OLTP system would be minimal and it wouldn't require any code changes (to the OLTP system) at all.
For fast, accurate and documented assistance in answering your questions, please read this article.
Understanding and using APPLY, (I) and (II) Paul White
Hidden RBAR: Triangular Joins / The "Numbers" or "Tally" Table: What it is and how it replaces a loop Jeff Moden
November 7, 2018 at 6:21 am
This option will not be viable for us, As our data is already there inside the SQL server.
November 7, 2018 at 6:28 am
azhar.iqbal499 - Wednesday, November 7, 2018 6:21 AMThis option will not be viable for us, As our data is already there inside the SQL server.
This does not sound like a restriction. You can commence replication at any time.
Replication is an efficient, lightweight means of providing a copy of some or all of your data for reporting. Superficially, it would appear to be a good fit for your requirements.
For fast, accurate and documented assistance in answering your questions, please read this article.
Understanding and using APPLY, (I) and (II) Paul White
Hidden RBAR: Triangular Joins / The "Numbers" or "Tally" Table: What it is and how it replaces a loop Jeff Moden
November 7, 2018 at 7:05 am
azhar.iqbal499 - Wednesday, November 7, 2018 1:46 AMActually I am working over Drilling Software which insert 1 row a into a table after five second. We Pass Some columns as parameter to a SP for Each row. These sps are called after every insert and it should not impact the OLTP. These SP are used to build some R Model so they needs Parameters for each row.
Client suggest me implement Service Broker for this. But for me it is extra overhead to manage Service Queue for just calling Procedure.
So What I did, on every insert of Row, I add same row in Audit table through after trigger. Trigger is only for INSERT. Then Loop on this table to call sp and mark the Flag isExecuted=TRUE, so that i don't pick record next time.
I can create multiple SPs to run them parallel on the basis of ID identity column in the Audit table. I will move this stuff into a job and job will run continuously to cater new records in a base table.
is that make sense?
Any better idea would be highly appreciated.Thanks in Advance.
And you have set this up for 200 tables? Does that also mean that you have 200 separate 'audit tables'?
The absence of evidence is not evidence of absence
- Martin Rees
The absence of consumable DDL, sample data and desired results is, however, evidence of the absence of my response
- Phil Parkin
November 7, 2018 at 9:44 am
Audit Table will be only one and it will be deleted for older data of one day back.
November 7, 2018 at 10:45 am
azhar.iqbal499 - Wednesday, November 7, 2018 9:44 AMAudit Table will be only one and it will be deleted for older data of one day back.
So the requirement to execute against the 90 million existing rows has vanished?
The absence of evidence is not evidence of absence
- Martin Rees
The absence of consumable DDL, sample data and desired results is, however, evidence of the absence of my response
- Phil Parkin
November 8, 2018 at 1:15 am
For Audit Table we store table Name to identify each table and we will delete older data for one day.
Viewing 15 posts - 1 through 15 (of 22 total)
You must be logged in to reply to this topic. Login to reply