I have the following queries:

EXPLAIN (ANALYZE, VERBOSE, COSTS, BUFFERS, TIMING)
select    […]
                from      f_calc_service   a11,
                                d_patient_type                a12
                where   a11.d_patient_pop_id in (336)
                         and a11.d_patient_type_id = a12.id
                         and a12.short_name = 'I'
                group by              a11.d_rate_schedule_id,
                                a11.d_payer_id,
                                a11.d_patient_pop_id,
                                a11.d_patient_type_id
;

And

EXPLAIN (ANALYZE, VERBOSE, COSTS, BUFFERS, TIMING)
select     […]
                from      f_calc_service   a11,
                                d_patient_type                a12
                where   a11.d_patient_pop_id in (336)
                         and a11.d_patient_type_id = a12.id
                         and a12.short_name = 'O'
                group by              a11.d_rate_schedule_id,
                                a11.d_payer_id,
                                a11.d_patient_pop_id,
                                a11.d_patient_type_id
;

Making this one change from short_name = ‘I’ to short_name = ‘O’ changes the 
query execution from 200k ms to 280ms. The first one chooses a Nested Loop, the 
second chooses a hash join. How do I get them both to choose the same? There 
are no values for d_patient_pop_id in (336) and short_name = ‘I’.

Thanks!

Dan


Reply via email to