Home Database Mysql Tutorial bitmap 索引和 B-tree 索引在使用中如何选择

bitmap 索引和 B-tree 索引在使用中如何选择

Jun 07, 2016 pm 05:55 PM
B-Tree bitmap index

现在,我们知道优化器如何对这些技术做出反应,清楚地说明 bitmap 索引和 B-tree 索引各自的最好应用

现在,我们知道优化器如何对这些技术做出反应,清楚地说明 bitmap 索引和 B-tree 索引各自的最好应用。
在 GENDER 列适当地带一个 bitmap 索引,在 SAL 列上创建另外一个位图索引,然后执行一些查询。在这些列上,用 B-tree 索引重新执行查询。
从 TEST_NORMAL 表,查询工资为如下的男员工:
1000
1500
2000
2500
3000
3500
4000
4500
因此:
SQL> select * from test_normal
2 where sal in (1000,1500,2000,2500,3000,3500,4000,4500,5000) and GENDER='M';
已选择444行。

执行计划
----------------------------------------------------------
Plan hash value: 4115571900
--------------------------------------------------------------------------------------------------
| Id | Operation | Name | Rows | Bytes | Cost(%CPU)| Time |
--------------------------------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | 1 | 39 | 1 (0)| 00:00:01 |
|* 1 | TABLE ACCESS BY INDEX ROWID | TEST_NORMAL | 1 | 39 | 1 (0)| 00:00:01 |
| 2 | BITMAP CONVERSION TO ROWIDS| | | | | |
|* 3 | BITMAP INDEX SINGLE VALUE | NORMAL_GENDER_BMX | | | | |
--------------------------------------------------------------------------------------------------
Predicate Information (identified by operation id):
---------------------------------------------------
1 - filter("SAL"=1000 OR "SAL"=1500 OR "SAL"=2000 OR "SAL"=2500 OR "SAL"=3000
OR
"SAL"=3500 OR "SAL"=4000 OR "SAL"=4500 OR "SAL"=5000)
3 - access("GENDER"='M')

统计信息
----------------------------------------------------------
0 recursive calls
0 db block gets
6280 consistent gets
0 physical reads
0 redo size
25451 bytes sent via SQL*Net to client
839 bytes received via SQL*Net from client
31 SQL*Net roundtrips to/from client
0 sorts (memory)
0 sorts (disk)
444 rows processed
SQL>
这是一个典型的数据仓库查询,不要再 OLTP(On-Line Transaction Processing,联机事务处理系统)系统上执行。下面是 bitmap 索引的结果:
而 B-tree 索引的查询:
SQL> select * from test_normal
2 where sal in (1000,1500,2000,2500,3000,3500,4000,4500,5000) and GENDER='M';

已选择444行。

执行计划
----------------------------------------------------------
Plan hash value: 654360527
-------------------------------------------------------------------------------------------------
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
-------------------------------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | 1 | 39 | 2 (0)| 00:00:01 |
|* 1 | TABLE ACCESS BY INDEX ROWID| TEST_NORMAL | 1 | 39 | 2 (0)| 00:00:01 |
|* 2 | INDEX RANGE SCAN | NORMAL_GENDER_IDX | 1 | | 2 (0)| 00:00:01 |
-------------------------------------------------------------------------------------------------
Predicate Information (identified by operation id):
---------------------------------------------------
1 - filter("SAL"=1000 OR "SAL"=1500 OR "SAL"=2000 OR "SAL"=2500 OR "SAL"=3000
OR
"SAL"=3500 OR "SAL"=4000 OR "SAL"=4500 OR "SAL"=5000)
2 - access("GENDER"='M')

统计信息
----------------------------------------------------------
0 recursive calls
0 db block gets
6854 consistent gets
0 physical reads
0 redo size
25451 bytes sent via SQL*Net to client
839 bytes received via SQL*Net from client
31 SQL*Net roundtrips to/from client
0 sorts (memory)
0 sorts (disk)
444 rows processed
SQL>
对 B-tree 索引,优化器选择了全表扫描,而在 bitmap 索引的情况下,使用了索引。可以通过 IO 推断出性能。
一般,bitmap 索引对 DSS 最合适,而不管基数怎么样,原因如下:

对于 bitmap 索引,优化器可能高效低相应包含 AND、OR 或 XOR 的查询。(Oracle 支持动态的 B-tree 到 bitmap 转换,但是效率不是很高。
对 bitmap 索引,当查询或计数 null 时,优化器会响应查询。null 值也被 bitmap 索引索引(这不同于 B-tree 索引)。

更重要的是,DSS 系统的 bitmap 索引支持 ad hoc 查询,而 B-tree 索引则不。更特别地,如果你有带 50 列的一个表,而用户频繁查询它们中的 10 个——或所有 10 个列的组合,或一个列——创建 B-tree 索引将会很困难。如果你在这些所有的列上创建 10 个 bitmap 索引,那么所有的查询都会被这些索引响应,而不论是在 10 个列上查询,还是 4、6 个列,或只一个列。AND_EQUAL 优化器提示为 B-tree 索引提供这个功能,但是不能超过 5 个索引。bitmap 索引就没有这个限制。

相比之下,B-tree 索引很适合 OLTP 应用程序,这样的系统用户查询比较常规(在部署前,可以调整),与 ad hoc 查询相对,它不是很频繁,在飞业务高峰时间执行。因为,OLTP 系统经常更新和删除,所以,在这种情况下,bitmap 索引可以导致一个严重的锁问题。

这里的数据是很明显。两个索引目标相同:尽可能快地返回结果。但选择使用哪个完全取决于应用的类型,而不是基数的水平。

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

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

Hot Article

Roblox: Bubble Gum Simulator Infinity - How To Get And Use Royal Keys
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Nordhold: Fusion System, Explained
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Mandragora: Whispers Of The Witch Tree - How To Unlock The Grappling Hook
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Hot Topics

Java Tutorial
1669
14
PHP Tutorial
1273
29
C# Tutorial
1256
24
How to fix 100% disk usage on Windows 11 How to fix 100% disk usage on Windows 11 Apr 20, 2023 pm 12:58 PM

How to Fix 100% Disk Usage on Windows 11 The straightforward way to find the problematic application or service causing 100% disk usage is to use Task Manager. To open Task Manager, right-click on the Start menu and select Task Manager. Click the Disk column header to see what's using the most resources. From there, you'll have a good idea of ​​where to start. However, the problem may be more serious than simply closing an application or disabling a service. Read on to find more potential causes of problems and how to fix them. Disabling SuperfetchSuperfetch feature (also known as SysMain in Windows 11) helps reduce startup time by accessing prefetch files

Here are 6 ways to fix Windows 11 search bar not available. Here are 6 ways to fix Windows 11 search bar not available. May 08, 2023 pm 10:25 PM

If your search bar isn't working in Windows 11, there are a few quick ways to get it up and running in no time! Any Microsoft operating system can experience glitches from time to time, and the latest operating systems are not exempt from this rule. Additionally, as pointed out by user u/zebra_head1 on Reddit, the same error appears on Windows 11 with 22H2Build22621.1413. Users complained that the option to toggle the taskbar search box randomly disappeared. Therefore, you must be prepared for any situation. Why can't I type in the search bar on my computer? The inability to type on the computer can be attributed to different factors and processes. Here are some things you should be aware of: Ctfmon.

How to hide files and folders and remove them from search in Windows 11? How to hide files and folders and remove them from search in Windows 11? Apr 26, 2023 pm 11:07 PM

<h2>How to Hide Files and Folders from Search on Windows 11</h2><p>The first thing we need to look at is customizing the location of Windows Search files. By skipping these specific locations, you should be able to see results faster while also hiding any files you want to protect. </p><p>If you want to exclude files and folders from searches on Windows 11, use the following steps: </p><ol&

What are the Oracle index types? What are the Oracle index types? Nov 16, 2023 am 09:59 AM

Oracle index types include: 1. B-Tree index; 2. Bitmap index; 3. Function index; 4. Hash index; 5. Reverse key index; 6. Local index; 7. Global index; 8. Domain index ; 9. Bitmap connection index; 10. Composite index. Detailed introduction: 1. B-Tree index is a self-balancing tree data structure that can efficiently support concurrent operations. In Oracle database, B-Tree index is the most commonly used index type; 2. Bit Graph index is an index type based on bitmap algorithm and so on.

Windows 11 Outlook Search Not Working: 6 Fixes Windows 11 Outlook Search Not Working: 6 Fixes Apr 22, 2023 pm 09:46 PM

Run the Search and Indexing Troubleshooter in Outlook One of the more straightforward fixes you can start is to run the Search and Indexing Troubleshooter. To run the troubleshooter on Windows 11: Click the Start button or press the Windows key and select Settings from the menu. When Settings opens, select System > Troubleshooting > Additional Troubleshooting. Scroll down on the right side, find SearchandIndexing and click the Run button. Select Outlook Search to return no results and continue with the on-screen instructions. When you run it, the troubleshooter will automatically identify and fix the problem. After running the troubleshooter, open Outlook and see if the search is working properly. like

PHP returns the string from the start position to the end position of a string in another string PHP returns the string from the start position to the end position of a string in another string Mar 21, 2024 am 10:31 AM

This article will explain in detail how PHP returns the string from the start position to the end position of a string in another string. The editor thinks it is quite practical, so I share it with you as a reference. I hope you will finish reading this article. You can gain something from this article. Use the substr() function in PHP to extract substrings from a string. The substr() function can extract characters within a specified range from a string. The syntax is as follows: substr(string,start,length) where: string: the original string from which the substring is to be extracted. start: The index of the starting position of the substring (starting from 0). length (optional): The length of the substring. If not specified, then

How to improve the efficiency of data grouping and data aggregation in PHP and MySQL through indexes? How to improve the efficiency of data grouping and data aggregation in PHP and MySQL through indexes? Oct 15, 2023 am 11:39 AM

How to improve the efficiency of data grouping and data aggregation in PHP and MySQL through indexes? Introduction: PHP and MySQL are currently the most widely used programming languages ​​and database management systems, and are often used to build web applications and process large amounts of data. Data grouping and data aggregation are common operations when processing large amounts of data, but if indexes are not designed and used appropriately, these operations can become very inefficient. This article will introduce how to use indexes to improve the efficiency of data grouping and data aggregation in PHP and MySQL, and improve

How to solve the problem that the index exceeds the array limit How to solve the problem that the index exceeds the array limit Nov 15, 2023 pm 05:22 PM

The solutions are: 1. Check whether the index value is correct: first confirm whether your index value exceeds the length range of the array. The index of the array starts from 0, so the maximum index value should be the array length minus 1; 2. Check the loop boundary conditions: If you use the index for array access in a loop, make sure the loop boundary conditions are correct; 3. Initialize the array: Before using an array, make sure that the array has been initialized correctly; 4. Use exception handling: You can use the exception handling mechanism in the program to catch errors where the index exceeds the bounds of the array, and handle it accordingly.

See all articles