Bug #18827 It is very slowly when the where statment include function
Submitted: 6 Apr 2006 5:46 Modified: 6 Apr 2006 10:48
Reporter: lucols lucols Email Updates:
Status: Not a Bug Impact on me:
None 
Category:MySQL Server Severity:S2 (Serious)
Version:5.0 OS:Any (all)
Assigned to: CPU Architecture:Any

[6 Apr 2006 5:46] lucols lucols
Description:
create table ab(id  int(11) NOT NULL auto_increment, code varchar(16),
status integer, PRIMARY KEY  (`ID`)  ) ;

insert 20000 row data ;

select like this:
select count(id) from ab where status=5;
It is very fase abut 2 seconds. 

Then use function in where condition,like this:
Create Function: CREATE FUNCTION `getStatus`(valueKey varchar(32)) RETURNS int(11)
BEGIN 
IF valueKey='REGISTERED' THEN
        return 5;
ELSEIF valueKey='FIRE' THEN
       return 6;
ELSE
     return 0;
END IF;
END

select count(id) from ab where status=getStatus('REGISTERED');
 
It will cost more time, may be 3 minutes.

I use mysqlcheck and all tables is OK.

So Bug or real performance ? and who can tell me how slove this problem?

How to repeat:
HARDWARE :  HP ML150, 1G RAM /2.1 XENO  CPU/ 73G SCSI HD 
OS: REDHAT AS 4
[6 Apr 2006 10:48] Hartmut Holzgraefe
We're sorry, but the bug system is not the appropriate forum for 
asking help on using MySQL products. Your problem is not the result 
of a bug.

Support on using our products is available both free in our forums
at http://forums.mysql.com and for a reasonable fee direct from our
skilled support engineers at http://www.mysql.com/support/

Thank you for your interest in MySQL.