Use top level join instead of subquery in hold queue position query
authormiker <miker@dcc99617-32d9-48b4-a31d-7c20da2025e4>
Tue, 19 Apr 2011 19:56:04 +0000 (19:56 +0000)
committermiker <miker@dcc99617-32d9-48b4-a31d-7c20da2025e4>
Tue, 19 Apr 2011 19:56:04 +0000 (19:56 +0000)
This is more readily optimized by the Postgres planer.

Note also, for very large data sets (lots of holds, on the order of 100k+ active), the following is also advised:

 ALTER TABLE action.hold_copy_map alter column target_copy SET statistics 500, alter column hold set statistics 500;
 ANALYZE action.hold_copy_map;

This gives the planner better data about the hold-copy-map n-distinct.

git-svn-id: svn://svn.open-ils.org/ILS/trunk@20221 dcc99617-32d9-48b4-a31d-7c20da2025e4

Open-ILS/src/perlmods/lib/OpenILS/Application/Circ/Holds.pm

index 696cd06..6ce8691 100644 (file)
@@ -1065,7 +1065,19 @@ sub retrieve_hold_queue_status_impl {
         # fetch cut_in_line and request_time since they're in the order_by
         # and we're asking for distinct values
         select => {ahr => ['id', 'cut_in_line', 'request_time']},
-        from   => { ahr => 'ahcm' },
+        from   => {
+            ahr => {
+                'ahcm' => {
+                    join => {
+                        'ahcm2' => {
+                            'class' => 'ahcm',
+                            'field' => 'target_copy',
+                            'fkey'  => 'target_copy'
+                        }
+                    }
+                }
+            }
+        },
         order_by => [
             {
                 "class" => "ahr",
@@ -1078,15 +1090,7 @@ sub retrieve_hold_queue_status_impl {
         ],
         distinct => 1,
         where => {
-            '+ahcm' => {
-                target_copy => {
-                    in => {
-                        select => {ahcm => ['target_copy']},
-                        from   => 'ahcm',
-                        where  => {hold => $hold->id}
-                    } 
-                } 
-            }
+            '+ahcm2' => { hold => $hold->id }
         }
     });