After importing openacs.org users, forums and messages I discovered that it took literally several minutes to load the APM's home page. Th…
Show more
After importing openacs.org users, forums and messages I discovered that ittook literally several minutes to load the APM's home page. This was dueto a rather stupid subselect of the form:select count(*)from content_revisions rwhere r.revision_id = content_item.get_latest_revision(item_id)where item_id comes from the package versions table.It's stupid in both PG and Oracle because get_latest_revision alreadyjoins the latest_revision_id value from cr_items with the contentrevisions table thus a simple check for a null return by get_latest_revisionwould be sufficient.It's *really* stupid in Oracle because Oracle won't use the index onrevision_id when checking NULLs so we get two sequential scans of thecr_revisions table tucked into that one itty-bitty subquery (itself calledonce for each package version in ths system).Which explains why I hadn't noticed it while working on scalability testingin PG - PG uses the index because its btree index structure handles NULLs.Meaning this query only fell apart at a rate of O(log2(R)) rather than O(R)as in Oracle (R being the number of revision objects in the system).My solution was to rewrite the subselect using "case" rather than "count(*)"and also to speed up get_latest_revision by having it check for NULL andreturn NULL immediately rather than execute the query (in PG this isaccomplished by declaring the function "isstrict", and the executor won'teven call the function if the argument's NULL, making it REALLY fast!).
Show less