Oracle 10g - optimize WHERE IS NOT NULL

后端 未结 9 1834
长情又很酷
长情又很酷 2020-12-13 20:56

We have Oracle 10g and we need to query 1 table (no joins) and filter out rows where 1 of the columns is null. When we do this - WHERE OurColumn IS NOT NULL - we get a full

9条回答
  •  北海茫月
    2020-12-13 21:26

    Using hints should be done only as a work around rather than a solution.

    As mentioned in other answers, the null value is not available in B-TREE indexes.

    Since you know that you have mostly null values in this column, would you be able to replace the null value by a range for instance.

    That really depends on your column and the nature of your data but typically, if your column is a date type for instance:

    where mydatecolumn is not null Can be translated in a rule saying: I want all rows which have a date.

    Then you can most definitely do this: where mydatecolumn <=sysdate (in oracle)

    This will return all rows with a date and ommit null values while taking advantage of the index on that column without using any hints.

提交回复
热议问题