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



BCP queryout speed Expand / Collapse
Author
Message
Posted Wednesday, November 18, 2009 11:47 AM
Grasshopper

GrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopper

Group: General Forum Members
Last Login: Friday, March 12, 2010 11:08 AM
Points: 22, Visits: 257
Hi,

I have a stored procedure that takes about 10 seconds to run directly on the server in QA. The proc is a series of select statements and only returns about 10 - 20 rows.

If I use this same proc in a BCP queryout command, it takes 2.5 minutes to complete.

sproc command in QA (takes 10 seconds):
exec [MyDB].[dbo].[MySproc]

BCP command (take 2.5 minutes):
declare @sql varchar(200)
select @sql = 'bcp "exec [MyDB].[dbo].[MySproc]" queryout \\server\share\filename.txt -c -T'
exec master..xp_cmdshell @sql

I can see the filename.txt is created immedialtely with 0 bytes. 2.5 minutes later the resutls are written to the file and the file is closed.

Thanks for any help.


When running the BCP command in QA, the output shows:
NULL
Starting copy...
NULL
13 rows copied.
Network packet size (bytes): 4098
Clock Time (ms.): total 10625
NULL
Post #821055
Posted Thursday, November 19, 2009 10:38 AM
Grasshopper

GrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopper

Group: General Forum Members
Last Login: Friday, March 12, 2010 11:08 AM
Points: 22, Visits: 257
More strange findings when using BCP:
The proc has a cursor. I added an audit log step to the proc so it inserts audit info to another table.
When I run the proc from Query Analyzer it runs as expected and logs data for each step of the cursor as expected.
When I run this using the above BCP command, it writes double records to the audit table:
audit record 1
audit record 2
audit record 1
audit record 2

Post #821795
« Prev Topic | Next Topic »


Permissions Expand / Collapse