oracle index

1. Create an index

CREATE INDEX     index_name   ON Indexed table (index field) TABLESPACE tablespace

2. Delete the index

drop index index_name

3. Notes on Indexing

1) The index should be created on the column of the table involved in the "Where" or "and" part of the SQL statement.    

2) Index is used in Order by. It should be noted that all the columns in the order by are included in the same index and maintain the order in the index, and all the columns in the order by must be defined as non-null, otherwise the index will be invalid.    

 3) Avoid changing the type of index columns.       

            例如:select * from EMP              where EMP_TYPE='123'       

                     In fact, when Oracle executes, it will execute the following statement:             

                     select * from EMP              where EMP_TYPE=to_number('123')       

                     This type conversion does not occur on the indexed column, so the index is still valid, but if it is written like this, the index will be invalid.          

                     select * from EMP           where to_number(EMP_TYPE)=123      

                     The index is invalid because the type of the indexed column has changed.    

 4) Create indexes on columns that are often used in joins, which can speed up joins. These columns are mainly foreign keys.    

 5) Create an index on the primary key column, which can enforce the uniqueness of the column and organize the arrangement of the data in the table.

 6) For columns whose column values ​​are frequently modified, it is not suitable to create an index, because adding an index will reduce the modification performance. Similarly, increasing the modification performance will reduce the index performance.

 7) Indexes should not be added for columns with few data values, because the data rows of the result set occupy a large proportion of the data rows in the table, and adding indexes cannot increase the retrieval speed.

8) Special attention in the Where clause is that not all index columns will be valid.    

           E.g:       

                 a) The use of "!=" in the where clause makes the index invalid,       

                  b) In addition, the use of "||" character splicing will also cause the index to fail.

                  c) There are also the same index columns that cannot be used for comparison, which will also cause the index to fail.

                 d) IS NULL and IS NOT NULL will also cause the index to fail.

                 e) The use of the function will also cause the index to fail  

                 f) the use of wildcards, so it will also fail             

- we create an index on name;

create index index_name on student( ' name ' ); --The following way oracle does not apply to the name index select * from student where name like ' %wish% ' ; -- If the wildcard appears in other places in the string, the optimizer can Use index; as follows: select * from student where name like ' wish% ';

             g) the use of not, so it will also be invalid



Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325723737&siteId=291194637