Can Multiple Indexes Work Together?

前端 未结 9 1350
情书的邮戳
情书的邮戳 2021-02-19 07:13

Suppose I have a database table with two fields, \"foo\" and \"bar\". Neither of them are unique, but each of them are indexed. However, rather than being indexed together, th

9条回答
  •  陌清茗
    陌清茗 (楼主)
    2021-02-19 07:56

    Yes, you can give "hints" with the query to Oracle. These hints are disguised as comments ("/* HINT */") to the database and are mainly vendor specific. So one hint for one database will not work on an other database.

    I would use index hints here, the first hint for the small table. See here.

    On the other hand, if you often search over these two fields, why not create an index on these two? I do not have the right syntax, but it would be something like

    CREATE INDEX IX_BAR_AND_FOO on sometable(bar,foo);
    

    This way data retrieval should be pretty fast. And in case the concatenation is unique hten you simply create a unique index which should be lightning fast.

提交回复
热议问题