Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 
        
Home       Members    Calendar    Who's On


Add to briefcase 1234»»»

Parallel Processing Expand / Collapse
Author
Message
Posted Sunday, October 11, 2009 10:08 PM
SSC-Enthusiastic

SSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-Enthusiastic

Group: General Forum Members
Last Login: Tuesday, August 27, 2013 11:09 PM
Points: 162, Visits: 263
Comments posted to this topic are about the item Parallel Processing
Post #801372
Posted Monday, October 12, 2009 2:30 AM
Grasshopper

GrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopper

Group: General Forum Members
Last Login: Monday, October 12, 2009 3:16 AM
Points: 14, Visits: 5
This is an excellent article the gave an idea have to solve some problems that arise from the need of paraller processing. Thank you very very much.
As all we want is right resource planning I show in the following article that its better to create temporary tables and use INSERT INTO instead of SELECT INTO. As the article says its a resources matter.
The article is here:http://www.sqlservercentral.com/articles/Basic+Querying/temptablesinsqlserver/1279/
Thank you.
Post #801421
Posted Monday, October 12, 2009 2:36 AM
Grasshopper

GrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopper

Group: General Forum Members
Last Login: Monday, October 12, 2009 3:16 AM
Points: 14, Visits: 5
As I am new to SQL i cannot understand why you are using the statement
SELECT * INTO #LockHelp FROM Rainfall_Events WITH (TABLOCKX) WHERE 1=2. This statement does not fetch any rows?
I't must be somenthing about the lock time, bit can you explain me why you are using "WHERE 1=2"?
Thank you
Post #801424
Posted Monday, October 12, 2009 3:12 AM


Old Hand

Old HandOld HandOld HandOld HandOld HandOld HandOld HandOld Hand

Group: General Forum Members
Last Login: Friday, July 29, 2011 4:14 AM
Points: 318, Visits: 198
iermis (10/12/2009)
As I am new to SQL i cannot understand why you are using the statement
SELECT * INTO #LockHelp FROM Rainfall_Events WITH (TABLOCKX) WHERE 1=2. This statement does not fetch any rows?
It must be something about the lock time, bit can you explain me why you are using "WHERE 1=2"?
Thank you


I think Sunny is using this "WHERE 1 = 2" for creating the #LockHelp table only, having no data.
But not sure why, because he has not refer #LockHelp in the SP.
Post #801437
Posted Monday, October 12, 2009 3:14 AM


Old Hand

Old HandOld HandOld HandOld HandOld HandOld HandOld HandOld Hand

Group: General Forum Members
Last Login: Friday, July 29, 2011 4:14 AM
Points: 318, Visits: 198
Nice article. Keep it up.
Post #801439
Posted Monday, October 12, 2009 3:16 AM
SSC-Enthusiastic

SSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-Enthusiastic

Group: General Forum Members
Last Login: Tuesday, August 27, 2013 11:09 PM
Points: 162, Visits: 263
Hi iermis

Thanks for the comments.
The query you mentioned is only for getting a Table Lock on the table. We dont actually need any records from the table but at the same time we want to have the table locked from the Rest_OrphanLocks SP until the records are marked as processed. The condition "1=2" does exactly that. It does not spend time retrieving records but locks the table. #LockHelp Temporary table is optional. We could as well have a SELECT query instead of SELECT INTO

Thanks
Satish More
Post #801441
Posted Monday, October 12, 2009 3:52 AM
SSC-Enthusiastic

SSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-Enthusiastic

Group: General Forum Members
Last Login: Tuesday, August 27, 2013 11:09 PM
Points: 162, Visits: 263
mohd.nizamuddin (10/12/2009)

I think Sunny is using this "WHERE 1 = 2" for creating the #LockHelp table only, having no data.
But not sure why, because he has not refer #LockHelp in the SP.


Thanks Nizamuddin. #LockHelp is optional. You can as well have only a SELECT query instead of SELECT INTO. The only difference is that it returns an empty result set back to the SP caller

Thanks
Satish More
Post #801456
Posted Monday, October 12, 2009 4:02 AM
Grasshopper

GrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopper

Group: General Forum Members
Last Login: Tuesday, September 30, 2014 11:29 PM
Points: 13, Visits: 26
Thank you all for your fast replies.
Post #801460
Posted Monday, October 12, 2009 4:33 AM


SSCommitted

SSCommittedSSCommittedSSCommittedSSCommittedSSCommittedSSCommittedSSCommittedSSCommitted

Group: General Forum Members
Last Login: Wednesday, November 19, 2014 2:22 PM
Points: 1,570, Visits: 683
I recently (within the last 2 years) created a system to monitor our SQL instances from a central instance. Without going into details about the whole process, I had a requirement to run multiple tasks to retrieve data from the monitored instances in parallel (one or more instances unavailable would cause delays in retrieving data from all the other instances).
There's an easier way to do this than messing with lock hints, use the UPDATE ... OUTPUT format of the UPDATE query. Here's a snippet of the code that I use:

    -- ******************************************************************************************
-- Create the local temp tables used in this proc
CREATE TABLE #DRT_Update (
DataRetrievalTaskID INT)
-- ******************************************************************************************

-- ******************************************************************************************
-- Clear the temp table ...
ProcessNextServer:
DELETE #DRT_Update
-- ******************************************************************************************

-- ******************************************************************************************
-- Get the next Data Retrieval Task to be processed - set the status to 2 for the record selected.
UPDATE DataRetrievalTask
SET [Status] = 2
OUTPUT inserted.DataRetrievalTaskID
INTO #DRT_Update
WHERE DataRetrievalTaskID = (SELECT MIN(DataRetrievalTaskID)
FROM DataRetrievalTask
WHERE [Status] = 1
AND StartTime <= GETDATE() )
-- ******************************************************************************************

This process is easily scalable - I just have to create another job to execute the Stored Proc to add another process. This way, you dont have to worry about Locks etc - the SQL Engine does it for you.



Post #801466
Posted Monday, October 12, 2009 4:39 AM
Grasshopper

GrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopper

Group: General Forum Members
Last Login: Tuesday, September 30, 2014 11:29 PM
Points: 13, Visits: 26
Can you explain the code?
Post #801467
« Prev Topic | Next Topic »

Add to briefcase 1234»»»

Permissions Expand / Collapse