Database Views and Indexes Self-Study Notes

view

A view is a table derived from one or more tables (or views). The view is different from the table (sometimes it is different from the view, also known as the base table--Base Table), the view is a virtual table, that is, the data corresponding to the view is not actually stored, and only the definition of the view is stored in the database. When the data of the view is operated, the system operates the basic table associated with the view according to the definition of the view.

The role of the view:

(1) The view can simplify the user's operation

(2) The view mechanism enables users to query the same data in different ways

(3) Views provide a certain degree of logical independence for database reconstruction

    --create view--  

   create or replace view v_student as select * from student;   --retrieve
        data  
        from view-- select * from v_student; --delete  
        view--  

  drop view v_student; 

Modification of views : Single-table views are generally used for query and modification, which will change the data of the basic table, and  multi-table views are generally used for querying and do not change the data of the basic table.

Disadvantages of views: Disadvantages: 
① Poor performance
  The database must convert the view query into a query on the basic table. If the view is defined by a complex multi-table query, then even a simple query of the view, the database must It becomes a complex combination that takes time. 
②Restriction of modification
  When the user tries to modify some information of the view, the database must convert it into modification of some information of the basic table. For simple views, this is very convenient, but for more complex attempts , which may not be modifiable.

When defining database objects, views cannot be defined indiscriminately. The advantages and disadvantages of views should be weighed and the views should be defined reasonably.

index

The index is not for you, but for the database itself. The index is just to make your query faster.

Index creation:

First, create a simple index on the table. Duplicate values ​​are allowed:
CREATE INDEX index_name

ON table_name (column_name)

Second, create a unique index on the table. A unique index means that no two rows can have the same index value.
CREATE UNIQUE INDEX index_name

ON table_name (column_name)

important point:

1. The index should not be stored in the same tablespace as the table; 

2. Do not have too many indexes in a table;

3. For large tables and frequently used tables, it is best not to add indexes during production; 

If a large table is indexed, the data retrieved is greater than 5% to 10% of the total, and the efficiency of using index scan will be greatly reduced. If the amount of data retrieved through the index is more than 50% of the total, it is not as fast as a full table scan at this time. 

4. For tables with a small amount of data, do not create separate indexes for tables that are used infrequently;

5. When several conditions are used together in the query condition, it is suitable to build a composite index. Otherwise, do not build a composite index. When a non-first field is referenced alone, a full table scan will occur; 
before Oracle9i, only the leading index of the index was used. Composite index can only be used when

6. When querying, the where condition does not deal with the columns of the index, but needs to deal with the following conditional fields. Otherwise, the index on this column will not be used. 

Factors that affect database indexes:

1. Adjust the design of the data structure. This part is completed before the development of the information system. Programmers need to consider whether to use the partition function of the ORACLE database and whether to build an index for frequently accessed database tables.

2. Adjust the application structure design. This part is also completed before the development of the information system. In this step, the programmer needs to consider what kind of architecture the application uses, whether to use the traditional Client/Server two-tier architecture or the three-tier architecture of Browser/Web/Database. . Different application architectures require different database resources.
3. Adjust the database SQL statement. The execution of the application will ultimately come down to the execution of the SQL statement in the database, so the execution efficiency of the SQL statement ultimately determines the performance of the ORACLE database. ORACLE recommends using the ORACLE statement optimizer (Oracle Optimizer) and row lock manager (row-level manager) to adjust and optimize SQL statements.
4. Adjust the server memory allocation. Memory allocation is optimized during the operation of the information system. The database administrator can adjust the size of the data buffer, log buffer and shared pool in the database system global area (SGA area) according to the database operation status; you can also adjust the program global area. (PGA area) size. It should be noted that the larger the SGA area is, the better. If the SGA area is too large, it will occupy the memory used by the operating system and cause page swapping of virtual memory, which will reduce the system.

Guess you like

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