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
# 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",
],
distinct => 1,
where => {
- '+ahcm' => {
- target_copy => {
- in => {
- select => {ahcm => ['target_copy']},
- from => 'ahcm',
- where => {hold => $hold->id}
- }
- }
- }
+ '+ahcm2' => { hold => $hold->id }
}
});