Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible to create index on view columns?

When I am creating an index on a view, it shows the following error:

ORA-01702: a view is not appropriate here

create view xx_emp for select * from emp; 

What is the reason behind it?

like image 308
guru Avatar asked Jul 02 '15 15:07

guru


People also ask

Can you create indexes on views?

Creating a unique clustered index on a view improves query performance because the view is stored in the database in the same way a table with a clustered index is stored. The query optimizer may use indexed views to speed up the query execution.

Is it possible to create an index on views in SQL?

Oracle SQL standards do not support creating indexes on views. If you need to index documents whose contents are in different tables, you can create a data storage preference using the USER_DATASTORE object.

Can we add index in views in mysql?

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).

Can you index a view Postgres?

PostgreSQL UsagePostgreSQL doesn't support view indexes, but does provide similar functionality with Materialized Views. Queries associated with materialized views are run and the view data is populated when the REFRESH command is issued.


1 Answers

You cannot create an index over a view, which is just a query.

You can, instead, create an index over a materialized view. A materialized view is a table which is created by evaluating a view, so that you can create an index over it. Keep in mind, however, that a materialized view is not updated for each modification of the base table(s) over which it is defined, so you should REFRESH it when it must be recalculated.

like image 109
Renzo Avatar answered Nov 15 '22 22:11

Renzo