Issue with Oracle bind variables not using index properly

后端 未结 4 1424
执念已碎
执念已碎 2020-12-06 14:16

In my scenario, the following query runs fast (0.5 seconds on a table with 70 million rows):

select * from Purchases
where (purchase_id = 1700656396)
         


        
4条回答
  •  萌比男神i
    2020-12-06 14:53

    Just a quick question: I guess the following non-parameterized query will also run for 1.5 minutes?

    select * from Purchases
    where (1700656396 IS NULL OR purchase_id    = 1700656396)
    and   ('some-name' IS NULL OR purchase_name  = 'some-name')
    and   (12       IS NULL OR purchase_price = 12)
    

    If yes, the problem is not the bind variables but the lack of indexes.

    EDIT The problem is, Oracle cannot decide to use the index when generating the plan for the parametrized query

提交回复
热议问题