
CREATE TABLE t (
  id int NOT NULL,
  PRIMARY KEY (id)
);

INSERT t 
SELECT seq FROM seq_1_to_20000;

DROP FUNCTION IF EXISTS GetId;
CREATE DEFINER = 'root'@'%'
FUNCTION GetId(id int(11))
  RETURNS int(11)
  READS SQL DATA
BEGIN
  RETURN id; 
END;

SELECT
  s.id1, s.Id2, t.id id3
FROM 
(SELECT
  seq id1,
  GetId(seq) Id2
FROM seq_1_to_100 s) s
  JOIN t ON t.id = s.id1;

SELECT
  s.id1, s.Id2, t.id id3
FROM 
(SELECT
  seq id1,
  GetId(seq) Id2
FROM seq_1_to_100 s) s
  JOIN t ON t.id = s.id2;
