如何为动态搜索字符串创建索引 [英] How to create index for dynamic search strings

查看:161
本文介绍了如何为动态搜索字符串创建索引的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个小DB,仅用于学术目的,我最多有对象表。
我在Power Designer中创建了一个实体关系模型(ERM),默认情况下,程序会为每个表创建序列ID的索引。

I have a little DB, for academic purpose only, and I have object tables at most. I've created a entity-relationship model (ERM) in Power Designer and the program, by default, creates index for the serial id's for each table.


  1. 我想知道如何在查询中使用索引
    。我希望
    想要通过其ID找到一个产品,
    但是使用它的索引。

  2. 是否可以从supplierf中选择
    的值,其中s.name
    LIKE'%search%'按s.name
    顺序使用索引来执行像
    这样的搜索?我知道可以为名称创建
    索引,但对于搜索
    ,我不知道
    的工作原理。

让我说,我确实知道Oracle决定何时或是否值得在查询中使用索引,但我可能必须至少尝试使用我的索引BD项目

Let me say, that I do know that Oracle decides when or if it's worth using index in a query, but I may have to give, at least, a try on using indexs in my BD project

推荐答案

1。
通过将列定义为 PRIMARY KEY (这就是您的id列最有可能的位置),Oracle隐含地为此列创建索引。当你选择 WHERE id = 123 时,它很可能决定使用该索引。您可以在查询中提供提示,以使Oracle使用该索引(在大多数情况下) ),但这对您来说不是必需的。

1. By defining a column as PRIMARY KEY (that's what your id column most likely is), Oracle implicitely creates an index for this column. It will most likely decide to use that index when you have a select with WHERE id=123). You can provide a hint in your query to make Oracle use the index (in most cases), but that should not be necessary for you.

2。
Oracle不太可能使用 LIKE 的索引(除非你知道你的文本以搜索到的字符串开头,你可以使用'xyz%')。有关更多信息,请参见 Tony Andrews的帖子关于何时以及如何使用索引进行全表扫描。

2. It is unlikely for Oracle to use an index for LIKE (unless you know that your text starts with the searched string and you can use 'xyz%'). See Tony Andrews' post for more information about when and how to use an index for full table scans.

关于带有文本索引的Oracle LIKE子句搜索应该提供有关处理全文搜索的方法的信息。

The article about Oracle LIKE clause searches with text indexes should provide information about a way to handle full text searches.

这篇关于如何为动态搜索字符串创建索引的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆