Mysl hangs when calling function inside select I have a problem with MySQL. I have a query:

select distinct a.continent_code, a.country_code, a.city_code
from t_lst_ip4 a
where a.idncode = (select f_get_ip4_code(in_ip4_desc));


select f_get_ip4_code(in_ip4_desc) 
by itself is a function that always returns -1; 

it looks like this:

delimiter $$
use `geoloc`$$
drop function if exists `test1`$$
use `geoloc`$$
create function `geoloc`.`test1`
(a int) returns int
begin
    return -1;
end;
$$
delimiter ;


When running this function separately, it works fine and fast.

When calling mentioned SELECT with just '-1' (that function always returns) it works fine.

I guess it has something to do with calling a function inside select?
separately everything works fine.

I guess function executes as many times as there are rows.

So if I have 3M rows, the function will execute 3M time.

I left only 3K entries in the table and now that select runs fast.

Is this how functions are originally executed inside SELECT?
Consider adding the keyword DETERMINISTIC to the CREATE FUNCTION.