Welcome to the Oracle community forum and interact with 2 million technical staff. As we all know, indexing can greatly improve the database query efficiency. However, if the index is improperly used, such as using an inappropriate index in an inappropriate place, it will be counterproductive. What indexes should be used for the table as shown in? I borrowed this
Welcome to the Oracle community forum and interact with 2 million technical staff> as we all know, indexing can greatly improve the database query efficiency. However, if the index is improperly used, such as using an inappropriate index in an inappropriate place, it will be counterproductive. What indexes should be used for the table as shown in? I borrowed this
Welcome to the Oracle community forum and interact with 2 million technical staff> enter
As we all know, indexes can greatly improve the efficiency of database queries. However, if the index is improperly used, such as using an inappropriate index in an inappropriate place, it will be counterproductive. What indexes should be used for the table as shown in? I will take this opportunity to discuss with you the usage time and precautions of Bitmap indexes.
As we all know, indexes can greatly improve the efficiency of database queries. However, if the index is improperly used, such as using an inappropriate index in an inappropriate place, it will be counterproductive. What indexes should be used for the table as shown in? I will take this opportunity to discuss with you the usage time and precautions of Bitmap indexes.
I. B-tree index Defects
In practice, the B-tree index is the most common index in Oracle databases. For example, when you use the Create Index statement to Create an Index, the B-tree Index is used by default. In the B-tree index, the sorted index column and its corresponding Rowid column value are saved in the index. However, in some special cases, such as columns with a small base, using this B-tree index will reduce the query efficiency of the database.
In the Oracle database, the base number indicates the number of non-repeated values that a column may have. For example, SEX refers to the gender of an employee. Generally, there are only two values for men and women (1 for men and 0 for women). The base is 2. Assume that an enterprise wants to organize all the female employees of the company to go out for a tour as a gift for Women's Day. To this end, you need to query the information of all female employees in the company. If the B-tree index is added to the Gender column, the result is counterproductive. The query efficiency is not improved, but decreased.
If you create a B-tree index on a column with a small base and query it, the system returns a large number of records. Therefore, this is not a highly selective index and does not significantly increase the query speed. Of course, it doesn't mean that B-tree indexes are not good, but that B-tree indexes are useless.
Ii. Features and use time of Bitmap indexes
In databases (including SQL Server databases), for columns with a small base, if there are only a few fixed values, such as gender and marital status in the table above, if you want to create an index for it, you should use a bitmap index instead of a B-tree index.
Why can bitmap indexes increase the query speed of tables with a small base? This is mainly because when creating a bitmap index, the database often scans the entire table and creates a bitmap for each value of the index column (the name of the bitmap index also comes from this ). In this bitmap, each row in the table uses a single element to indicate whether the row contains the value of the bitmap's index column. The corresponding relationship between the bitwise AND row ROWID is completed through the receivables function in the bitmap index. In this way, bitmap indexes can implement the same functions as B-tree indexes with a completely different internal mechanism.
It is also worth mentioning that, for the B-tree index, if the operator symbols such as AND are used in the query Condition Statement, the query efficiency will be greatly reduced. Therefore, in database optimization, we recommend that you do not use these operators instead of other operators. However, if Bitmap indexes are used, there is no such concern. As shown in the preceding example, you can use the following statement to query married women.
Select t. *, t. rowid
From userinfo t
Where t. merrent= 'married 'and t. sex = 0
When this query references some columns that have created Bitmap indexes, these bitmaps can be easily combined with the and or operator to find the desired data. When the database is processing in the background, it first uses the created bitmap for logical operations, and then calculates the number of 1 in the result bitmap to query all records meeting the conditions. If you still need to change the data after the result is queried, you only need to map the value of the ROWID column corresponding to the 1-bit element in the result bitmap.
Iii. Restrictions on the Use of Bitmap indexes
Although Bitmap indexes can play a better effect than B-tree indexes in some cases. However, it should be noted that it is not effective on any occasions. As shown in the preceding example, data query efficiency is reduced if you use the employee ID or employee name column. Therefore, its use is still limited. As in the case above, in general, bitmap indexes can only be used in "Columns with a relatively small base" and "operations requiring a sum or sum" to achieve better results than B-tree indexes. In other cases, it is better to use the B index or function index.
In Oracle databases, there are B-tree indexes, bitmap indexes, and function indexes. The specific index should be treated according to different situations. As database applications become increasingly complex, one B-tree index alone is no longer enough. If a column contains expressions or functions, the B-tree index or bitmap index cannot be used. Only function indexes are used. For database experts, creating and managing indexes may not be difficult. Just a few simple statements are required. It is difficult to select an appropriate index based on the actual situation.