> How do you explain the cost is about ten times lower in the 2nd query > than the first ?
Function call cost ?
Can you EXPLAIN ANALYZE ?