Search Postgresql Archives

Re: Unnecessary function calls

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Markus Schiltknecht wrote:
Hi,

when using LIMIT, how do I tell the planner to only call a function for
rows it returns?

An example: I want to fetch the top five categories. A function
get_category_text_path(cat_id int) returns the textual representation of
the category. For that I do something like:

SELECT id, get_category_text_path(id)
   FROM category
   ORDER BY rank
   LIMIT 5

Unfortunately this takes very long because it calls
get_category_text_path() for all of the 450'000 categories in the table.
But I only need the full text path of the top five rows.

SELECT id, get_category_text_path(id)
FROM (
    SELECT id FROM category ORDER BY rank LIMIT 5
) AS foo

HTH
--
  Richard Huxton
  Archonet Ltd


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Index of Archives]     [Postgresql Jobs]     [Postgresql Admin]     [Postgresql Performance]     [Linux Clusters]     [PHP Home]     [PHP on Windows]     [Kernel Newbies]     [PHP Classes]     [PHP Books]     [PHP Databases]     [Postgresql & PHP]     [Yosemite]
  Powered by Linux