Ow Mun Heng wrote: > how can I debug or diagnose where the issues lies? Explain analyse > doesn't do much since this is a Function Scan anyway. Take them out of the function and EXPLAIN ANALYZE them as plain SQL. Note that you should take the parameters out of the literal, so you need to do something like PREPARE foo AS SELECT ... replace code with $1, etc ... EXPLAIN ANALYZE EXECUTE foo(code, ...) Otherwise they would be treated as constants so the queries would be planned differently. (untested, so correct the syntax appropriately) -- Alvaro Herrera http://www.amazon.com/gp/registry/DXLWNGRJD34J "Before you were born your parents weren't as boring as they are now. They got that way paying your bills, cleaning up your room and listening to you tell them how idealistic you are." -- Charles J. Sykes' advice to teenagers ---------------------------(end of broadcast)--------------------------- TIP 2: Don't 'kill -9' the postmaster