Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is difference between INDEX and VIEW in MySQL

Which one is fast either Index or View both are used for optimization purpose both are implement on table's column so any one explain which one is more faster and what is difference between both of them and which scenario we use view and index.

like image 582
Ashutosh SIngh Avatar asked Jun 13 '14 04:06

Ashutosh SIngh


People also ask

What is the difference between view and indexed view?

An indexed view has a unique clustered index. The unique clustered index is stored in SQL Server and updated like any other clustered index. An indexed view is more significant compared to standard views that involve complex processing of large numbers of rows, such as aggregating lots of data, or joining many rows.

What is the use of view and index in SQL?

A SQL index is used to retrieve data from a database very fast. Indexing a table or view is, without a doubt, one of the best ways to improve the performance of queries and applications. A SQL index is a quick lookup table for finding records users need to search frequently.

Can MySQL view have index?

It is not possible to create an index on a view. Indexes can be used for views processed using the merge algorithm. However, a view that is processed with the temptable algorithm is unable to take advantage of indexes on its underlying tables (although indexes can be used during generation of the temporary tables).

What is difference between view and table in MySQL?

View and Table both are integral parts of a relational database, and both terms are used interchangeably. The view is a result of an SQL query and it is a virtual table, whereas a Table is formed up of rows and columns that store the information of any object and be used to retrieve that data whenever required.


1 Answers

VIEW

  • View is a logical table. It is a physical object which stores data logically. View just refers to data that is tored in base tables.
  • A view is a logical entity. It is a SQL statement stored in the database in the system tablespace. Data for a view is built in a table created by the database engine in the TEMP tablespace.

INDEX

  • Indexes are pointres that maps to the physical address of data. So by using indexes data manipulation becomes faster.
  • An index is a performance-tuning method of allowing faster retrieval of records. An index creates an entry for each value that appears in the indexed columns.

ANALOGY:

Suppose in a shop, assume you have multiple racks. Categorizing each rack based on the items saved is like creating an index. So, you would know where exactly to look for to find a particular item. This is indexing.

In the same shop, you want to know multiple data, say, the Products, inventory, Sales data and stuff as a consolidated report, then it can be compared to a view.

Hope this analogy explains when you have to use a view and when you have to use an index!

like image 83
Nishanthi Grashia Avatar answered Oct 02 '22 01:10

Nishanthi Grashia