Oracle索引之B-Tree和Bitmap索引对比
B树索引是所有大型关系数据库毕用的技术,也是oracle数据库默认的索引技术。基数:指的是你要创建索引的列中所包含的不同键值的数
B树索引是所有大型关系数据库毕用的技术,也是Oracle数据库默认的索引技术。
基数:指的是你要创建索引的列中所包含的不同键值的数量。例如我们的列是性别,那么它的键值就是男、女所以你的索引基数是2.
oracle中每个表的行都有一个rowid,用于标记这个行在数据库中的位置。
关于索引:
B-TREE索引,结构如下:
root
/ | \
branch1 ........
/|\ ......................
leaf1......
leaf节点的结构是这样的:
|索引头|列长度|列内容|rowid(s)|
一个叶子节点的大小大概是8192*8bit,因此一个字段的长度即使是50,那么一个节点大概能分成100个子节点,那么100万的记录,也只需要3级节点即可索引完毕,因此一般b-tree的深度不超过4级,这样根据b-tree来查找一条记录,最多只需遍历4个节点找到rowid,再根据rowid查找磁盘即可得到最终记录数据。
对某列查询的结果集记录数如果通常都小于7%,则应该在该列添加索引。对b-tree来说,where xx is null条件是不会利用索引的,因此建议这种列应该设置默认值,以避免该列的值存在null的情况,同样group by 中如果该列有null索引也可能无效。
bitmap索引:
bitmap索引的结构也是树形结构,但是叶子节点的结构与b-tree不一样。bitmap叶子节点的结果大概如下:
......
其中bitmap的内容是110010100011100001这样的01组合形式,,它的长度与start-rowid和end-rowid之间包含的rowid数量一致。这样假设范围内第9个rowid对应列的内容是key1,那么kei1对应的bitmap中第9个字符的值就是1,否则就是0。同样每个块的大小是8192*8,那么一个bitmap索引的叶子节点大概能索引10000条记录。
bitmap索引对null的字段依然有效,具体null的值在bitmap中是取0还是专门有个keyX的值是null来区分需要再查证。bitmap索引对or条件的查询效果非常好,它不适应与索引列的值经常变化的情况,如果索引列的值经常变化,那么对bitmap索引将是灾难性的,因为它要锁定所有相关的叶子节点所在的块来更新bitmap的值,它适用于决策支持系统。
更多Oracle相关信息见Oracle 专题页面 ?tid=12

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

Full table scanning may be faster in MySQL than using indexes. Specific cases include: 1) the data volume is small; 2) when the query returns a large amount of data; 3) when the index column is not highly selective; 4) when the complex query. By analyzing query plans, optimizing indexes, avoiding over-index and regularly maintaining tables, you can make the best choices in practical applications.

Yes, MySQL can be installed on Windows 7, and although Microsoft has stopped supporting Windows 7, MySQL is still compatible with it. However, the following points should be noted during the installation process: Download the MySQL installer for Windows. Select the appropriate version of MySQL (community or enterprise). Select the appropriate installation directory and character set during the installation process. Set the root user password and keep it properly. Connect to the database for testing. Note the compatibility and security issues on Windows 7, and it is recommended to upgrade to a supported operating system.

InnoDB's full-text search capabilities are very powerful, which can significantly improve database query efficiency and ability to process large amounts of text data. 1) InnoDB implements full-text search through inverted indexing, supporting basic and advanced search queries. 2) Use MATCH and AGAINST keywords to search, support Boolean mode and phrase search. 3) Optimization methods include using word segmentation technology, periodic rebuilding of indexes and adjusting cache size to improve performance and accuracy.

The difference between clustered index and non-clustered index is: 1. Clustered index stores data rows in the index structure, which is suitable for querying by primary key and range. 2. The non-clustered index stores index key values and pointers to data rows, and is suitable for non-primary key column queries.

MySQL is an open source relational database management system. 1) Create database and tables: Use the CREATEDATABASE and CREATETABLE commands. 2) Basic operations: INSERT, UPDATE, DELETE and SELECT. 3) Advanced operations: JOIN, subquery and transaction processing. 4) Debugging skills: Check syntax, data type and permissions. 5) Optimization suggestions: Use indexes, avoid SELECT* and use transactions.

In MySQL database, the relationship between the user and the database is defined by permissions and tables. The user has a username and password to access the database. Permissions are granted through the GRANT command, while the table is created by the CREATE TABLE command. To establish a relationship between a user and a database, you need to create a database, create a user, and then grant permissions.

MySQL and MariaDB can coexist, but need to be configured with caution. The key is to allocate different port numbers and data directories to each database, and adjust parameters such as memory allocation and cache size. Connection pooling, application configuration, and version differences also need to be considered and need to be carefully tested and planned to avoid pitfalls. Running two databases simultaneously can cause performance problems in situations where resources are limited.

MySQL supports four index types: B-Tree, Hash, Full-text, and Spatial. 1.B-Tree index is suitable for equal value search, range query and sorting. 2. Hash index is suitable for equal value searches, but does not support range query and sorting. 3. Full-text index is used for full-text search and is suitable for processing large amounts of text data. 4. Spatial index is used for geospatial data query and is suitable for GIS applications.
