Its declared immutable , it queries the same table , its recursive and it queries another custom function also.
fyi dir_name is a simple plperlu function. my ($dir) = @_; $dir =~ s/&/and/g; $dir =~ s/&/and/g; $dir =~ s/[^a-zA-Z0-9]+/_/g; return $dir;