Why does PostgreSQL treat my query differently in a function?
问题 I have a very simple query that is not much more complicated than: select * from table_name where id = 1234 ...it takes less than 50 milliseconds to run. Took that query and put it into a function: CREATE OR REPLACE FUNCTION pie(id_param integer) RETURNS SETOF record AS $BODY$ BEGIN RETURN QUERY SELECT * FROM table_name where id = id_param; END $BODY$ LANGUAGE plpgsql STABLE; This function when executed select * from pie(123); takes 22 seconds. If I hard code an integer in place of id_param,