postgresql with function wrap sql so slow?
问题 first sql explain analyse: explain analyse select * from ttq.ttq_post; Seq Scan on ttq_post (cost=10000000000.00..10000000014.71 rows=171 width=547) (actual time=0.005..0.027 rows=176 loops=1) Planning Time: 0.033 ms Execution Time: 0.041 ms but if use function wrap the same sql eg: create or replace function ttq.test_fn_slow() returns setof ttq.ttq_post language sql stable as $$ select * from ttq.ttq_post; $$ and exec blow function: explain analyse select ttq.test_fn_slow(); result: