SQL functions that can be inlined

Started by Jim Nasbyabout 15 years ago2 messages
#1Jim Nasby
jim@nasby.net

Is there any way to have the database tell you if a particular SQL function can be inlined?
--
Jim C. Nasby, Database Architect jim@nasby.net
512.569.9461 (cell) http://jim.nasby.net

#2Tom Lane
tgl@sss.pgh.pa.us
In reply to: Jim Nasby (#1)
Re: SQL functions that can be inlined

Jim Nasby <jim@nasby.net> writes:

Is there any way to have the database tell you if a particular SQL function can be inlined?

Easiest way is to EXPLAIN a query using it and see if it did get inlined.
For example,

regression=# create function foo(int) returns int as
regression-# 'select $1 + 1' language sql;
CREATE FUNCTION
regression=# explain verbose select foo(f1) from int4_tbl;
QUERY PLAN
---------------------------------------------------------------
Seq Scan on public.int4_tbl (cost=0.00..1.06 rows=5 width=4)
Output: (f1 + 1)
(2 rows)

regression=# create function foo2(int) returns int as
'select $1 + 1 limit 1' language sql;
CREATE FUNCTION
regression=# explain verbose select foo2(f1) from int4_tbl;
QUERY PLAN
---------------------------------------------------------------
Seq Scan on public.int4_tbl (cost=0.00..2.30 rows=5 width=4)
Output: foo2(f1)
(2 rows)

regards, tom lane