Do cursors use statistics?

MS SQL SERVER

    Next

  • 1. SQL SERVER 2005 x64 Crash when accessing data from Oracle 32bit system
    Im having an extremely frustrating time trying to get around this problem! We have a 64bit instance of SQL Server 2005 running soley on a Windows Server 2003 64bit box (i dont actually have the server specs available to me atm). There is another server running Windows Server 2003 32bit, and has an install of Oracle 9i that has a simple timestamp database running. We are setting up an automated ETL to grab data out of the Oracle database and insert it into the 64bit SQL server 2005 database. When this transfer is started the 64bit SQL server 2005 database locks up, and has to be taken offline and restarted. There was a test environment created for this process a few months ago and all was fine. The difference then was that the SQL server end was running in 32bit mode on a 32bit version of windows server. So i guess im basically asking is there some known issue with transferring data between 64bit servers and 32bit servers?!? Any help on this would be extremely appreciated, I appologise for lack of hardware information, but i am trying to organise this from a different country!
  • 2. How many hosts can you connect to a SAN ?
    Does anyone have some basics to how a SAN is laid out ? I was on the HDS site and we are looking at the USP1100 and I came across terms like Directors,etc, but wish there was some basics on SANs someplace.. Does anyone use USP1100 for SQL Servers and any pros and cons ?
  • 3. SQL and all that jazz.
    Hi, Im a non programmer SQL user, which recently discovered the wonders of database usage :) Ok, Now that my tables are ready for use, im trying to locate a ready made interface that i can let users query the database. any suggestion/help/smiles will be greatly appreciated.. thanks, 50.
  • 4. Is this join not possible?
    Ok maybe I am having a senior moment here or something, I thought this was something you could do, but maybe I am just remembering wrong. I am trying to join Customers and Addresses, but I only 1 a maximum of 1 address joined. So in other words, if I did a join and there was a customer w/ 5 addresses, that would result in 5 records being returned, and I just want it to give me 1 record with the first address joined. I am using this Select statement: SELECT C.*, A.* FROM Customers C LEFT OUTER JOIN (SELECT TOP 1 * FROM CustomerAddresses WHERE (CustomerAddresses.CustomerId = C.CustomerId)) AS A ON C.CustomerId = A.CustomerId It is saying that "C.CustomerId" is not valid in my nested select statement. I can probably do this with a join to a user defined function returning a table, but I could have sworn that what I was trying to do was do-able... Can anyone help?
  • 5. Modified image filegroup never get saved
    I'm testing out the SQL Server 2005 filegroup for Text/Image Filegroup. Problem: I created a table and gave the properties "Text/Image Filegroup" the value of the secondary filegroup, gave the properties "Filegroup or Partition Scheme Name" the value of primary file group. After I save it. Then I open it for edit again, the value of the properties "Text/Image Filegroup" was not showing secondary, instead, it show primary. I'd try a few times to change it, from primary to secondary, then save. After that open for modify again, it still revert back to primary filegroup. Seems like the changes I made to that particular properties can't be saved. Anyone can help? Thanks in advance. wodoy.peter

Do cursors use statistics?

Postby Mark » Sat, 26 Aug 2006 04:50:02 GMT

I have the following RPC which is followed by 2 fetches (of 100 rows)
and then a close.  Query returns 150 rows.

When I run it through the query analyzer, it runs fast.  Each time
through the VB app, the first set of 100 takes 20 seconds with over 10
M reads.  The second set takes 7 seconds with 2 M reads.

The only thing I can think of is that it is not using the stats.  Any
debugging ideas or advice?

the sgrp_ext is a view that joins a 9M row table to a 170M row table on
a single column


declare @P1 int
set @P1=180150009
declare @P2 int
set @P2=4
declare @P3 int
set @P3=1
declare @P4 int
set @P4=-1
exec sp_cursoropen @P1 output, N'SELECT SGRP_EXT.F_SGRP,
SGRP_EXT.F_PART, SGRP_EXT.F_PRCS, SGRP_EXT.F_TEST, SGRP_EXT.F_WKNO,
SGRP_EXT.F_JOB, SGRP_EXT.F_LOT, SGRP_EXT.F_SPLT, SGRP_EXT.F_EMPL,
SGRP_EXT.F_SGTM, SGRP_EXT.F_SGSZ, SGRP_EXT.F_FLAG, SGRP_EXT.F_SN,
SGRP_EXT.F_TSNO, SGRP_EXT.F_SBNO, SGRP_EXT.F_VAL, SGRP_EXT.F_DEF,
SGRP_EXT.F_GAGE FROM SGRP_EXT, PRCS_DAT WHERE
(SGRP_EXT.F_PRCS=PRCS_DAT.F_PRCS) AND SGRP_EXT.F_PART=1141815113 AND
(PRCS_DAT.F_PRGP=1141918205) AND (SGRP_EXT.F_SGTM BETWEEN 1149120000
AND 1157068799) AND SGRP_EXT.F_TEST=1141918846 ORDER BY SGRP_EXT.F_SGTM
DESC, SGRP_EXT.F_SGRP DESC, SGRP_EXT.F_TEST DESC, SGRP_EXT.F_TSNO,
SGRP_EXT.F_SBNO', @P2 output, @P3 output, @P4 output
select @P1, @P2, @P3, @P4


Re: Do cursors use statistics?

Postby Mike C# » Sat, 26 Aug 2006 05:38:25 GMT

Advice:  Get rid of the cursor.








Re: Do cursors use statistics?

Postby JXStern » Sat, 26 Aug 2006 10:21:48 GMT

I've never used sp_cursoropen, and can't even find it in my local copy
of BOL.  How about using TSQL cursor syntax, or finding a way to
specify "forward_only" or "fast_forward" attributes via the SP?

Default cursor types of dynamic can run pathologically slow, as you
are seeing.

J.







Re: Do cursors use statistics?

Postby Sue Hoegemeier » Wed, 30 Aug 2006 09:11:37 GMT

Yes they will statistics. sp_cursoropen is just what the API
uses to access the data - it's just doing what the driver
tells it to do through the application (via ADO,  ODBC,
etc). You would probably want to take a look at the VB end
of things as there are different settings on the application
end that could be affecting this.  

-Sue

On 24 Aug 2006 12:50:02 -0700, "Mark"





Similar Threads:

1.use UPDATE STATISTICS @table in a cursor

The script below is a cursor. I get the following error when I run it:
--{Server: Msg 170, Level 15, State 1, Line 14
Line 14: Incorrect syntax near '@table'.}--
The error is caused by this phrase: -- UPDATE STATISTICS @table --  How do I
resolve this.

***********************************************************
SET NOCOUNT ON
USE db_control
DECLARE @table varchar(10)
DECLARE EDI_cursor CURSOR FOR
SELECT table_name FROM INFORMATION_SCHEMA.TABLES
WHERE table_type ='Base Table'
ORDER BY table_name
OPEN  EDI_cursor
FETCH NEXT FROM  EDI_cursor
INTO @table
WHILE @@FETCH_STATUS = 0
BEGIN
select @table
UPDATE STATISTICS @table
FETCH NEXT FROM EDI_cursor
   INTO @table
END
CLOSE EDI_cursor
DEALLOCATE EDI_cursor
GO
**********************************************************


2.mdac 2.8 fails to execute a cursor fetch next when done via oledb (repost)

I have an SQL script that uses a cursor to update some rows. I loop  
through all the records using 'fetch next from mycursor'.

This works fine when executed in SQL Query Analyzer. When sending the very  
same script via OLEDB to the SQL Server I get an unspecified OLEDB
error. I could locate the spot where the error occurs the first time, it's  
at the 'fetch next'.

I did not test all available MDAC versions. But I succeeded with versions  
2.6 and 2.7SP1. Version 2.8, the latest one, gives me troubles.

Any hints, insights?

TIA
Rudi Wiener

3.Can this be done without a cursor?

Here's the senario.  I have a list of users who have received services
during the year.  I need a report that gives me the languages they speak
both year to date and month to date.  The challenge for me is to figure out
how to output something like this:

Language  MTD   YTD
English         2         2
French         0         1
German       1         1
Spanish       2          2

Here's some DDL:

CREATE TABLE #Services (
 UserId int,
 svcDate datetime
)

INSERT INTO #Services VALUES (1, '1/3/2003')
INSERT INTO #Services VALUES (2, '3/1/2003')
INSERT INTO #Services VALUES (2, '4/1/2003')
INSERT INTO #Services VALUES (3, '2/1/2003')
INSERT INTO #Services VALUES (4, '3/27/2003')
INSERT INTO #Services VALUES (3, '4/22/2003')

CREATE TABLE #Languages (
 UserID int,
 Language varchar(50)
)

INSERT INTO #Languages VALUES (1, 'French')
INSERT INTO #Languages VALUES (2, 'English')
INSERT INTO #Languages VALUES (3, 'Spanish')
INSERT INTO #Languages VALUES (4, 'German')

SELECT
 COUNT(a.UserID),
 b.Language
FROM #Services AS a
LEFT JOIN #Languages AS b ON a.UserId = b.UserId
WHERE a.svcDate >= '1/1/2003'
GROUP BY b.Language
ORDER BY b.Language

SELECT
 COUNT(a.UserId),
 b.Language
FROM #Services AS a
LEFT JOIN #Languages AS b ON a.UserId = b.UserId
WHERE a.svcDate >= '2/1/2003'
GROUP BY b.Language
ORDER BY b.Language

This gives me two separate tables but I want just one output as above.  Can
this be done without using a cursor?  Thanks.


4.mdac 2.8 fails to execute a cursor fetch next when done via oledb

I have an SQL script that uses a cursor to update some rows. I loop  
through all the records using 'fetch next from mycursor'.

This works fine when executed in SQL Query Analyzer. When sending the very  
same script via OLEDB to the SQL Server I get an unspecified OLEDB error.  
I could locate the spot where the error occurs the first time, it's at the  
'fetch next'.

I did not test all available MDAC versions. But I succeeded with versions  
2.6 and 2.7SP1. Version 2.8, the latest one, gives me troubles.

Any hints, insights?

TIA
Rudi Wiener

5.using a cursor with a cursor in transact-sql

6. using a cursor vs using a query

7. Deletion using multiple records without using cursor

8. Auto created statistics and missing statistics



Return to MS SQL SERVER

 

Who is online

Users browsing this forum: No registered users and 91 guest