Web Wiz - Green Windows Web Hosting

  New Posts New Posts RSS Feed - Error: The query has been canceled because
  FAQ FAQ  Forum Search   Events   Register Register  Login Login

Error: The query has been canceled because

 Post Reply Post Reply
Author
Cem Alacayir View Drop Down
Newbie
Newbie
Avatar

Joined: 15 January 2006
Location: Turkey
Status: Offline
Points: 4
Post Options Post Options   Thanks (0) Thanks(0)   Quote Cem Alacayir Quote  Post ReplyReply Direct Link To This Post Topic: Error: The query has been canceled because
    Posted: 04 July 2007 at 9:15pm

Microsoft OLE DB Provider for SQL Server error '80040e14'
The query has been canceled because the estimated cost
of this query (432) exceeds the configured threshold of 60.
Contact the system administrator.

 
I started to get the above error whenever I deleted a single post from a topic. The post was really deleted but the error was causing topic records to be orphaned thus the topics were disappearing from the forums. I found out that the delete query was successfull but another query just before the query that updates topic statistics was stopping the execution in delete_post.asp.
 
The query that was failing is
 

 'Check there are other Posts for the Topic, if not delete the topic as well 
 'Initalise the strSQL variable with an SQL statement to get the Threads from the database
 strSQL = "SELECT " & strDbTable & "Thread.Thread_ID " & _
 "FROM " & strDbTable & "Thread" & strDBNoLock & " " & _
 "WHERE " & strDbTable & "Thread.Topic_ID = "  & lngTopicID & " " & _
 "ORDER BY " & strDbTable & "Thread.Message_date ASC;"
 
 'Query the database
 rsCommon.Open strSQL, adoCon
 
 
 'If there are posts left in the database for this topic get some details for them
 If NOT rsCommon.EOF Then
  
  'Move to the last message in the topic to get the details of the last post
  rsCommon.MoveLast
  
  'Get the post ID of the last post
  lngLastPostID = CLng(rsCommon("Thread_ID"))
 End If
 
 'Close the recordset
 rsCommon.Close
 
It seems strange to me that a simple task like finding the last post id of the thread is determined with an inefficient code like this which costs too much in SQL Server. So I changed the code to a better version:
 

 strSQL = "SELECT MAX(" & strDbTable & "Thread.Thread_ID)" & _
 "FROM " & strDbTable & "Thread"  & strDBNoLock & " " & _
 "WHERE " & strDbTable & "Thread.Topic_ID = "  & lngTopicID
 rsCommon.Open strSQL, adoCon
 If NOT rsCommon.EOF Then
  If (rsCommon(0) <> "") Then lngLastPostID = CLng(rsCommon(0))
 End If
 rsCommon.Close
 
 
I hope Borg optimizes queries like this in version 9.0.


Edited by Cem Alacayir - 04 July 2007 at 9:17pm
Back to Top
WebWiz-Bruce View Drop Down
Admin Group
Admin Group
Avatar
Web Wiz Developer

Joined: 03 September 2001
Location: Bournemouth
Status: Offline
Points: 9844
Post Options Post Options   Thanks (0) Thanks(0)   Quote WebWiz-Bruce Quote  Post ReplyReply Direct Link To This Post Posted: 05 July 2007 at 9:07am
I think this page got missed in the last optimisation audit, but will certainly look at improving it.

I have a feeling though that for mySQL the MAX method is a bit buggy when you include a WHERE clause.
Back to Top
WebWiz-Bruce View Drop Down
Admin Group
Admin Group
Avatar
Web Wiz Developer

Joined: 03 September 2001
Location: Bournemouth
Status: Offline
Points: 9844
Post Options Post Options   Thanks (0) Thanks(0)   Quote WebWiz-Bruce Quote  Post ReplyReply Direct Link To This Post Posted: 05 July 2007 at 9:12am
The following should have the same type of performance improvement, but will ensure compatibility with all databases types used:-

strSQL = "SELECT " & strDBTop1 & " " & strDbTable & "Thread.Thread_ID " & _
    "FROM " & strDbTable & "Thread" & strDBNoLock & " " & _
    "WHERE " & strDbTable & "Thread.Topic_ID = "  & lngTopicID & " " & _
    "ORDER BY " & strDbTable & "Thread.Message_date ASC " & strDBLimit1 & ";"

Back to Top
Cem Alacayir View Drop Down
Newbie
Newbie
Avatar

Joined: 15 January 2006
Location: Turkey
Status: Offline
Points: 4
Post Options Post Options   Thanks (0) Thanks(0)   Quote Cem Alacayir Quote  Post ReplyReply Direct Link To This Post Posted: 05 July 2007 at 11:30am
Yes, this seems like a better version.
 
I don't know why but it seems "ORDER BY Thread.Message_date" costs too much in SQL Server for some reason but using strDBTop1 should improve it.
 
Thanks Borg.
Back to Top
WebWiz-Bruce View Drop Down
Admin Group
Admin Group
Avatar
Web Wiz Developer

Joined: 03 September 2001
Location: Bournemouth
Status: Offline
Points: 9844
Post Options Post Options   Thanks (0) Thanks(0)   Quote WebWiz-Bruce Quote  Post ReplyReply Direct Link To This Post Posted: 05 July 2007 at 11:41am
Not sure why it wasn't like that in the first place, seems stupid returning all the records then using a client side recordset move, when all we need is the 1 record.
Back to Top
 Post Reply Post Reply

Forum Jump Forum Permissions View Drop Down

Forum Software by Web Wiz Forums® version 12.08
Copyright ©2001-2026 Web Wiz Ltd.


Become a Fan on Facebook Follow us on X Connect with us on LinkedIn Web Wiz Blogs
About Web Wiz | Contact Web Wiz | Terms & Conditions | Cookies | Privacy Notice

Web Wiz is the trading name of Web Wiz Ltd. Company registration No. 05977755. Registered in England and Wales.
Registered office: Web Wiz Ltd, Unit 18, The Glenmore Centre, Fancy Road, Poole, Dorset, BH12 4FB, UK.

Prices exclude VAT at 20% unless otherwise stated. VAT No. GB988999105 - $, € prices shown as a guideline only.

Copyright ©2001-2026 Web Wiz Ltd. All rights reserved.