Icon View Thread

The following is the text of the current message along with any replies.
Messages 11 to 12 of 12 total
Thread Adding call to function vastly slows down query
Fri, Jun 24 2011 6:38 AMPermanent Link

Adam Brett

Orixa Systems

Dear Tim,

I think the main problem was in my newbie Function writing.

I wrote a version:

CREATE FUNCTION "COCOBodWeek" ()
RETURNS INTEGER
BEGIN
DECLARE RESULT INTEGER DEFAULT 0;
DECLARE tmp CURSOR FOR stmt;

PREPARE stmt FROM

  ' SELECT ID, ROUND(CAST((Current_date - YearStartDate()) as INTEGER) / 7) as COCOBodWeek '
 +' FROM PrimaryEvacuations WHERE ID = 10';

OPEN tmp;
    
FETCH FIRST FROM tmp ('COCOBodWeek') INTO RESULT;

RETURN RESULT;
END

I chose this version purely because I assumed a SQL Function had to call some sort of SQL Statement to generate a result ... very beginner-ish behaviour sorry.

Roy suggested the version:

ALTER FUNCTION "CocoBODWeek" ()
RETURNS INTEGER
BEGIN
 DECLARE RESULT INTEGER DEFAULT 0;
 SET RESULT = ROUND((CAST(Current_date - YearStartDate() as INTEGER)+1) / 7 TO 0);
 RETURN RESULT;
END

... substituting this internal function for my database-calling function speeded the query up from 20+ seconds to <1 second. I guess that calling even a single row query for everyone of the 100,000 rows of my primary table would be bound to have that sort of impact.
Mon, Jun 27 2011 5:24 PMPermanent Link

Tim Young [Elevate Software]

Elevate Software, Inc.

Avatar

Email timyoung@elevatesoft.com

Adam,

<< .. substituting this internal function for my database-calling function
speeded the query up from 20+ seconds to <1 second. I guess that calling
even a single row query for everyone of the 100,000 rows of my primary table
would be bound to have that sort of impact. >>

Nicely done. Smiley

--
Tim Young
Elevate Software
www.elevatesoft.com
« Previous PagePage 2 of 2
Jump to Page:  1 2
Image