Forum OpenACS Q&A: Optimizing query in acs-events

Collapse
Posted by Roberto Mello on
Hi all,

I was upgrading a 4.5 installation to 4.6. The upgrade to 4.6 died on the acs-events upgrade script, so I went to fix it. I found what I think is a very innefficient query and am trying to optimize it, so suggestions and pointers of places where I screwed up are appreciated 😊

Here's the original query (in a function):

FOR v_timespan in
    select *
      from time_intervals
     where interval_id in 
           (select interval_id
              from timespans 
              where timespan_id in 
                    (select timespan_id
                       from acs_events 
                      where recurrence_id = 
                             (select recurrence_id 
                                from acs_events 
                                where event_id = p_event_id)))

I'm thinking that it this case it would work to put everything in inner joins to get rid of the INs. I just woke up so I may be missing something obvious :) Comments?

Collapse
Posted by Tom Jackson on

Whoa! I guess whoever wrote that was in a big hurry. I wonder why the record is called v_timespan, shouldn't it be maybe v_time_interval, or something. I don't see anything.

Collapse
Posted by Don Baccus on
You've got it, Roberto.  Join ...