]> git.evergreen-ils.org Git - working/Evergreen.git/commit
LP#1234845: Performance improvement to evergreen.ranked_volumes() database function. collab/miker/lp1234845_ranked_volumes-rebased
authorhubert depesz lubaczewski <depesz@depesz.com>
Thu, 3 Oct 2013 18:26:33 +0000 (14:26 -0400)
committerMike Rylander <mrylander@gmail.com>
Mon, 24 Feb 2014 18:59:29 +0000 (13:59 -0500)
commit94288cbb2030c961b8c61de3fdf3fc4ef85e1df4
tree38d42e50cc6e1e91355fdcfc51087a33a26cd8f9
parente406e36122b07f97f1c6ec6d5397550b03949b1b
LP#1234845: Performance improvement to evergreen.ranked_volumes() database function.

For the client I analyzed logs from production Pg instance for ~ 10
days.

During this time, the single most time consuming query (summarized time
for all instances of the query, with different parameters) was:

SELECT * FROM unapi.bre ( ... ) AS "unapi.bre";

I profiled this function, and found that in my test case most of the
time (2.04s out of 2.06s, so ~ 99%) was spent in call to
unapi.holdings_xml() function.

When I profiled this function, I found that most of the time (sorry,
don't have the number now with me) was spent in call to
evergreen.ranked_volumes() function.

At this moment in my research something changed on the server I was
testing on, and all subsequent times were ~ 4-5 times lower, but the
ratios were more or less the same.

Anyway - call to evergreen.ranked_volumes() showed repeatable time (with
full caches/buffers) of ~ 380ms.

I modified the function by:
1. inlining actor.org_unit_descendants(?, ?)
2. inlining evergreen.rank_ou(?, ?, ?)
3. extracting depth calculation to separate call
4. switched to plpgsql (which gives me ability to use variables)
5. removed evergreen.rank_ou() and evergreen.rank_cp_status() from
   select clause - these are still in WINDOW definition, but they
   weren't used in the SELECT, so it's better to remove from there.
6. in passing renamed arguments to avoid name clash (argument depth vs.
   field depth)
7. in passing changed usage of $* to access parameters to using named
   parameters, for readability.

New function did the same work in ~ 18ms.

EDIT: Convert to SQL, keeping all of the improvements from depesz

Signed-off-by: Mike Rylander <mrylander@gmail.com>
Open-ILS/src/sql/Pg/990.schema.unapi.sql
Open-ILS/src/sql/Pg/upgrade/XXXX.function.ranked_volumes.sql [new file with mode: 0644]