Forum .LRN Q&A: slow select statement

Collapse
Posted by Tom Lodge on
Hi,

I have downloaded and installed the latest .LRN 1.0 beta 1, and am using OpenACS 4.6.2 beta 1, and postgres 7.2.1.  When I create a class, and then click on Class Home, things run very slowly.

It seems that this is down to a reasonably complex select statement (see end of this message), which on my (debian) machine, when I run under psql, takes a little under 30s to complete.  My machine is by no means slow - so if nobody else is seeing this problem, perhaps it is something to do with my installation...

The select statement is:

select file_storage__get_package_id(fs_objects.object_id) as package_id,
(CASE WHEN fs_objects.type = 'url' THEN (select site_node__url(site_nodes.node_id)
from site_nodes where site_nodes.object_id = file_storage__get_package_id(fs_objects.parent_id))
ELSE (select site_node__url(site_nodes.node_id)
from site_nodes where site_nodes.object_id = file_storage__get_package_id(fs_objects.object_id))
END) as url, fs_objects.object_id, fs_objects.file_upload_name, fs_objects.name, fs_objects.live_revision, fs_objects.type,
fs_objects.content_size from fs_objects
where fs_objects.parnt_id in (2368)
and 't' = acs_permission__permission_p(fs_objects.object_id, '290', 'read')
order by fs_objects.parent_id, fs_objects.sort_key, fs_objects.name;

Collapse
2: Re: slow select statement (response to 1)
Posted by Don Baccus on
Have you VACUUM ANALYZEd your database?
Collapse
3: Re: slow select statement (response to 1)
Posted by Tom Lodge on
I have now, speeds it up, thanks.  Now down to around 5 sec for the query to execute.
Collapse
4: Re: slow select statement (response to 1)
Posted by Jarkko Laine on
Tom,
you might want to make a script that vacuums your database automatically daily. If you're making a daily backup, that should of course be made before the vacuum, just in case it screws up your db.

The pg backup script (see documentation) makes also the vacuuming. You might want to check it for an example.

Collapse
5: Re: slow select statement (response to 4)
Posted by Tom Lodge on
JarkKo,

Thanks for the info.  Will do.

Collapse
6: Re: slow select statement (response to 4)
Posted by Tom Lodge on
Jarkko,

Many thanks - will do.

Collapse
7: Debian vacuum script (response to 4)
Posted by Andrew Piskorski on
Btw, the Debian PostgreSQL package ships with such a nigtly vacuum script. Basically, entries in /etc/cron.d/postgresql call /usr/lib/postgresql/bin/do.maintenance with various options.