Home  >  Article  >  Database  >  Does mysql view have an index?

Does mysql view have an index?

WBOY
WBOYOriginal
2022-03-02 15:32:264796browse

There is no index in the view in mysql. A view is a virtual table that does not actually exist in the database, so there is no primary key or index. Because the view has no rows and columns, it is essentially a statement. When the view is called, the system first executes the statement that generates the view, and then Query based on views.

Does mysql view have an index?

The operating environment of this tutorial: windows10 system, mysql8.0.22 version, Dell G3 computer.

Does mysql view have an index?

The view does not have an index. The view is a virtual table and does not really exist in the database, so there is no primary key or index because there are no rows at all. Sum columns are essentially statements. When you call a view, the database management system will first find the statement encapsulated in the view, first execute the statement that generates the view, and then query based on the view

In the view Indexes cannot be used, nor triggers can be used (indexes and triggers will be analyzed later)

It can be used with ordinary tables, and editing a SQL statement that joins a view and an ordinary table is allowed.

Regarding using views to update data (add, delete, modify), because the view itself has no data, these operations are directly applied to ordinary tables, but not all views can perform update operations. , if there are group by, join, subquery, union (unoin), aggregate function (sum/count, etc.), calculated field, DISTINCT, etc. in the view, the view cannot be updated, so our previous example cannot In fact, the update operation is mainly used for data retrieval, so there is no need to elaborate too much on the update.

The Essence of Views

Now the creation and use of views are relatively clear. Now we are ready to further understand the essence of views. We have repeatedly said before that a view is a virtual table. Without any data, each query just dynamically obtains data from an ordinary table and combines it, but it looks like a table. The principle is clear from the following figure:

Does mysql view have an index?

In fact, sometimes views are also used to restrict users' query operations on ordinary tables, and only corresponding views are given to such users. The select operation permission only allows them to read data from specific rows or columns. In this way, we do not need to directly use the database permission settings to limit the reading of rows and columns, and also avoid the trouble of permission refinement.

Recommended learning: mysql video tutorial

The above is the detailed content of Does mysql view have an index?. For more information, please follow other related articles on the PHP Chinese website!

Statement:
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