索引组织表中的MAPPING TABLE

Oracle支持在分区或非分区的索引组织表上创建位图索引,需要一个映射表(MAPPING TABLE)来存储逻辑ROWID。MAPPING TABLE是一个堆组织表,提供索引组织表行与映射表行的一对一映射。位图索引通过映射表的ROWID访问数据,而非直接使用索引组织表的物理ROWID。在索引组织表上创建位图索引时,必须先创建MAPPING TABLE。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

Oracle supports bitmap indexes on partitioned and nonpartitioned index-organized tables.A mapping table is required for creating bitmap indexes on an index-organized table.

The mapping table is a heap-organized table that stores logical rowids of the index-organized table. Specifically,each mapping table row stores one logical rowid for the corresponding index-organized table row. Thus,the mapping table provides one-to-one mapping between logical rowids of the index-organized table rows and physical rowids of the mapping table rows.

A bitmap index on an index-organized table is similar to that on a heap-organized table except that the rowids used in the bitmap index on an index-organized table are those of the mapping table as opposed to the base table. There is one mapping table for each index-organized table and it is used by all the bitmap indexes created on that index-organized table.

In both heap-organized and index-organized base tables, a bitmap index is accessed using a search key. If the key is found, the bitmap entry is converted to a physical rowid. In the case of heap-organized tables, this physical rowid is then used to access the base table. However, in the case of index-organized tables, the physical rowid is then used to access the mapping table. The access to the mapping table yields a logical rowid. This logical rowid is used to access the index-organized table.

Though a bitmap index on an index-organized table does not store logical rowids, it is still logical in nature.

大意是说:Oracle数据库支持在分区或者不分区的索引组织表(IOT)上创建位图索引。在向索引组织表创建位图索引的时候必须要有MAPPING TABLE。

MAPPING TABLE是一个HEAP表(即普通表),用来存储索引组织表的逻辑rowid。具体来说,MAPPING TABLE的每一行存储了一个逻辑rowid,用来关联索引组织表的行。因此,MAPPING TABLE的物理rowid和索引组织表的行之间产生了一对一的关联。因为索引组织表的rowid会经常变化,所以只有逻辑rowid,而不像普通表的行具有物理rowid,可以直接对应到具体的物理存放地点。在索引组织表上创建的位图索引和在普通HEAP表上创建的位图索引是类似的,只不过如果是索引组织表,那位图索引会使用MAPPING TABLE的rowid。在查询的时候,2种表都是通过key字段访问,在key字段找到之后,普通HEAP表会直接把key转换成rowid,然后通过rowid定位到具体的数据块中。但是如果是索引组织表,会通过key转换成rowid后,到MAPPING TABLE中去查找逻辑rowid,然后通过这个逻辑rowid去访问索引组织表里的数据。

SQL> create table t_testmap(eno number primary key,ename varchar2(10)) organization index;


Table created.


SQL> create bitmap index idx_map on t_testmap(ename);
create bitmap index idx_map on t_testmap(ename)
*
ERROR at line 1:
ORA-28669: bitmap index can not be created on an IOT with no mapping table

无法在没有mapping table的情况下给IOT创建位图索引。

SQL> create table t_testmap2(eno number primary key,ename varchar2(10)) organization index mapping table;


Table created.


SQL> create bitmap index idx_map on t_testmap2(ename);


Index created.

位图索引创建成功。

SQL> select table_name,iot_name,iot_type from user_tables;


TABLE_NAME IOT_NAME IOT_TYPE
------------------------------ ------------------------------ ---------------------
SYS_IOT_MAP_10258 T_TESTMAP2 IOT_MAPPING
T_TESTMAP2 IOT
T_TESTMAP IOT

SQL> select index_name, index_type, table_name, uniqueness from user_indexes;


INDEX_NAME INDEX_TYPE TABLE_NAME UNIQUENES
------------------------------ --------------------------- ------------------------------ ------------------
IDX_MAP BITMAP T_TESTMAP2 NONUNIQUE
SYS_IOT_TOP_10258 IOT - TOP T_TESTMAP2 UNIQUE
SYS_IOT_TOP_10256 IOT - TOP T_TESTMAP UNIQUE

这里可以看出索引组织表虽然是表,但是存储的结构是索引

SQL> drop table SYS_IOT_MAP_10258;
drop table SYS_IOT_MAP_10258
*
ERROR at line 1:
ORA-28668: cannot reference mapping table of an index-organized table

mapping table 无法被直接删除,但是可以通过move进行删除

SQL> alter table t_testmap2 move nomapping;
alter table t_testmap2 move nomapping
*
ERROR at line 1:
ORA-28670: mapping table cannot be dropped due to an existing bitmap index

在创建了bitmap index的时候,mapping table也无法被删除。

SQL> drop index idx_map;


Index dropped.

SQL> alter table t_testmap2 move nomapping;


Table altered.


SQL> select table_name,iot_name,iot_type from user_tables;


TABLE_NAME IOT_NAME IOT_TYPE
------------------------------ ------------------------------ ------------
T_TESTMAP2 IOT
T_TESTMAP IOT

这时再查询就发现mapping table被删除了。

SQL> select object_name, original_name, type from recyclebin;


no rows selected

而且这种删除不会把mapping table放入回收站。

如果因为误操作等原因想恢复mapping table,可以使用以下命令重建。

SQL> alter table t_testmap move mapping table;


Table altered.

SQL> select table_name,iot_name,iot_type from user_tables;


TABLE_NAME IOT_NAME IOT_TYPE
------------------------------ ----------------------- --------------------------
SYS_IOT_MAP_10256 T_TESTMAP IOT_MAPPING
T_TESTMAP2 IOT
T_TESTMAP IOT

此时mapping table又重新创建。

SQL> create bitmap index idx_map on t_testmap(ename);


Index created.

重新创建索引以进行下面的实验。

SQL> drop table t_testmap;


Table dropped.


SQL> select object_name, original_name, type from recyclebin;


OBJECT_NAME ORIGINAL_NAME TYPE
------------------------------ -------------------------------- -------------------------
BIN$tKX6TiUGBMLgQAB/AQATjQ==$0 IDX_MAP INDEX
BIN$tKX6TiUHBMLgQAB/AQATjQ==$0 SYS_IOT_TOP_10256 IOT TOP INDEX
SYS_IOT_MAP_10256 SYS_IOT_MAP_10256 IOT MAPPING TABLE
BIN$tKX6TiUIBMLgQAB/AQATjQ==$0 T_TESTMAP TABLE

如果直接删除表t_testmap,那么该索引组织表上关联的mapping table 和 bitmap index 会一起被放入回收站中。

SQL> flashback table t_testmap to before drop;


Flashback complete.


SQL> select table_name,iot_name,iot_type from user_tables;


TABLE_NAME IOT_NAME IOT_TYPE
------------------------------ ------------------------------ ------------
SYS_IOT_MAP_10256 T_TESTMAP IOT_MAPPING
T_TESTMAP IOT
T_TESTMAP2 IOT


SQL> select index_name, index_type, table_name from user_indexes;


INDEX_NAME INDEX_TYPE TABLE_NAME
------------------------------ -------- --------------------------- ----------------------
BIN$tKX6TiUGBMLgQAB/AQATjQ==$0   BITMAP        T_TESTMAP
BIN$tKX6TiUHBMLgQAB/AQATjQ==$0   IOT - TOP     T_TESTMAP
SYS_IOT_TOP_10258                           IOT - TOP      T_TESTMAP2

转自:http://blog.sina.com.cn/s/blog_68ea97d10101cmyn.html
<think>我们正在处理用户关于Elasticsearch索引mapping中algorithm配置的问题。根据引用内容,用户希望了解或修改algorithm相关的配置或使用方法。然而,在提供的引用中,并没有直接提到"algorithm"这个配置项。因此,我们需要结合Elasticsearch的知识来推断用户可能指的是什么。在Elasticsearch中,mapping的配置项通常包括字段的数据类型(如text,keyword,date等)以及类型相关的参数(如analyzer,index_options等)。用户提到的"algorithm"可能指的是以下几个方面:1.相似度算法(SimilarityAlgorithm):用于计算文档的相关性评分。Elasticsearch允许为每个字段设置相似度算法,例如BM25(默认)、经典相似度(TF/IDF)等。2.分词器(Tokenizer)或分词算法:在文本分析过程中,分词器负责将文本切分成词条(token)。Elasticsearch提供了多种内置的分词器(如standard、ik_max_word等),也可以自定义分词器。3.索引选项(index_options):控制哪些信息被存储到倒排索引中(如文档编号、词频、位置、偏移量等),这影响搜索和高亮的功能(如引用[2]所述)。4.其他与算法相关的配置,如向量相似度算法(用于向量字段)等。由于用户问题中提到了“algorithm”,并且引用[1]中提到了“param_similarity_index”和“default_field”,引用[2]中提到了index_options,引用[3]中提到了分词器的配置(analyzer和search_analyzer),我们推测用户可能关注的是相似度算法或分词算法。因此,我们将重点介绍相似度算法(Similarity)和分词算法(Analyzer)的配置和使用。###相似度算法(Similarity)配置在Elasticsearch中,可以为每个字段指定相似度算法。常见的相似度算法有:-BM25:默认的相似度算法,适用于大多数场景。-classic:使用TF/IDF(词频/逆文档频率)的经典相似度算法。-boolean:一个简单的布尔相似度,当不需要全文排序时使用。####配置示例在创建索引时,可以在mapping中为字段设置相似度算法。例如:```jsonPUT/my_index{"settings":{"index":{"similarity":{"my_similarity":{//自定义一个相似度配置,命名为my_similarity"type":"BM25",//使用BM25算法"b":0.75,//BM25的参数b"k1":1.2//BM25的参数k1}}}},"mappings":{"properties":{"title":{"type":"text","similarity":"my_similarity"//将自定义相似度应用于title字段},"content":{"type":"text","similarity":"BM25"//直接使用内置的BM25(默认,可以省略)}}}}```####使用说明-相似度配置通常在索引设置中定义,然后在mapping中引用。-内置的相似度算法(如BM25)可以直接在字段的mapping中使用,无需在settings中定义。-可以自定义相似度算法的参数(如BM25的k1和b)。###分词算法(Analyzer)配置分词算法由分析器(Analyzer)定义,通常包括:-字符过滤器(Characterfilters):处理原始文本,如去除HTML标签。-分词器(Tokenizer):将文本切分成词条。-词条过滤器(Tokenfilters):对词条进行处理,如转小写、同义词处理等。####配置示例在索引设置中定义分析器,然后在mapping中指定字段使用的分析器。```jsonPUT/my_index{"settings":{"analysis":{"analyzer":{"my_analyzer":{//自定义分析器"type":"custom","tokenizer":"ik_max_word",//使用ik分词器的最大化分词"filter":["lowercase"]//转为小写}}}},"mappings":{"properties":{"content":{"type":"text","analyzer":"my_analyzer",//索引时使用自定义分析器"search_analyzer":"ik_smart"//搜索时使用ik智能分词(可选,若不指定则使用analyzer)}}}}```####使用说明-`analyzer`参数指定索引时使用的分析器,用于建立倒排索引。-`search_analyzer`参数指定搜索时使用的分析器,用于处理查询字符串。如果不指定,则默认使用与`analyzer`相同的分析器。-可以使用Elasticsearch内置的分析器(如standard、simple等),也可以使用第三方分析器(如ik中文分词器),或者自定义分析器。###总结用户可能希望配置Elasticsearch索引mapping中的算法,主要包括相似度算法(Similarity)和分词算法(Analyzer)。相似度算法影响相关性评分,分词算法影响文本如何被索引和搜索。**注意**:在Elasticsearch中,没有直接名为“algorithm”的配置项,上述两种配置是最接近的。如果用户指的是其他算法(如向量相似度),则需要提供更多信息。§§相关问题§§1.Elasticsearch中有哪些内置的相似度算法?2.如何自定义分词器(Analyzer)?3.如何为不同的字段设置不同的相似度算法?4.在Elasticsearch中,如何配置中文分词器(如IK)?</think>### Elasticsearch 索引 Mapping 中 Algorithm 配置详解 在 Elasticsearch 中,`algorithm` 配置通常与**相似度算法(Similarity Algorithm)**相关,用于控制文档相关性评分(_score)的计算方式。以下是关键配置说明和使用示例: --- #### 一、核心配置参数 1. **相似度算法类型** 在 mapping 中通过 `similarity` 参数指定算法: ```json "properties": { "content": { "type": "text", "similarity": "BM25" // 指定算法类型 } } ``` - 内置算法选项: - `BM25`(默认):基于概率模型的改进算法,适合通用场景 - `classic`:TF/IDF 经典算法 - `boolean`:布尔模型,忽略词频 2. **算法参数调整** 针对 BM25 的调优(需在索引设置中预定义): ```json PUT /my_index { "settings": { "similarity": { "custom_bm25": { "type": "BM25", "b": 0.75, // 长度归一化参数(0~1) "k1": 1.2 // 词频饱和度参数 } } }, "mappings": { "properties": { "title": { "type": "text", "similarity": "custom_bm25" // 应用自定义算法 } } } } ``` - `b`:控制字段长度对评分的影响(值越高,长度影响越大) - `k1`:控制词频饱和度的非线性程度 --- #### 二、使用场景示例 1. **优化搜索结果相关性** 当需要提升精确匹配的重要性时: ```json PUT /product_index { "mappings": { "properties": { "product_name": { "type": "text", "similarity": "boolean" // 忽略词频,侧重匹配与否 } } } } ``` 2. **处理长文本字段** 调整 BM25 参数降低长度影响: ```json "similarity": { "long_text_similarity": { "type": "BM25", "b": 0.3 // 降低长度权重 } } ``` --- #### 三、注意事项 1. **算法选择建议**: - 默认 `BM25` 在多数场景效果最优 - 短文本(如标签)可尝试 `boolean` - 需要向后兼容时使用 `classic`(TF/IDF) 2. **限制条件**: - 算法配置需在**索引创建时**设定 - 已存在的字段修改算法需重建索引 - 自定义算法名称不能与内置算法冲突 > 引用说明:相似度算法参数调整参考了 Elasticsearch 官方文档对 BM25 的优化建议[^2],索引字段配置方法基于 mapping 声明规范[^3]。 --- ### 相关问题 1. 如何验证不同相似度算法对搜索结果的影响? 2. 在 Elasticsearch 中能否为不同字段分别设置相似度算法? 3. 除了 BM25,还有哪些高级相似度算法可用? 4. 如何通过查询参数临时覆盖索引中定义的相似度算法?
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值