Can I add an index on a view in mariaDB - sql

I need to create an index on a view in mariaDB. Is this possible?
Note that, I can't create an index on tables since admininstrator permissions are not given to access tables.

No, you cannot create indexes on a View in MariaDB.
Indeed, Views are not real relations, but simply aliases on relations (tables).
You could have created indexes on a Materialized View but MariaDB does not implement (in a native way) Materialized Views as of today.

Related

Materializing an existing view in Postgres

I have an existing view I need materialized. Ideally, I would drop the view and create a materialized one, but dropping the view would require a cascade drop and that would create a lot more work.
Is there an expression to change the view to a materialized one?

Rebuild database views

When you create a view, the column structure of the view is created and stored, and thus you can see it in object explorer:
When you alter the source data tables, sometimes things go wacky, because the view may have been built with "Select *" yet the schema created for you has the old information without the additional columns.
Does SQL Server have an easy way to rebuild the view schemas?
Do not use SELECT * in views. I say this as someone who has spent much too much time (in the past) debugging views that had this "feature".
When you do create a view in a production system, create it with SCHEMABINDING:
SCHEMABINDING
Binds the view to the schema of the underlying table or tables. When SCHEMABINDING is specified, the base table or tables cannot be modified in a way that would affect the view definition. The view definition itself must first be modified or dropped to remove dependencies on the table that is to be modified.
Although this adds an extra step when trying to modify tables, the increased resilience of the system is worth it.

What's the difference between a view and a query?

In SSMS and MySQLWorkbench a view is the SQL that generates a result set. In Access those are called queries. Is a view the same as a query?
A view is essentially a stored/predefined query. Depending on the database in question, views may additionally have indexes defined against them, have referential integrity defined on them, and/or be materialized (pre-queried and persisted to disk).

How to update master table while updating materialized view

I have three sites,one site contians the employees table, while the other sites have materialized view of employees table .
This is how i created the materialized views on the other sites.
CREATE MATERIALIZED VIEW employeesMV
REFRESH FAST
FOR UPDATE
AS
SELECT * FROM manager.employees#managerlink;
so i just want to know how to update the master table employees after i make changes such as (insert or update) on the materialized view.
Thank you in advance.
By default, materialized view can't be updated. However, if you use FOR UPDATE clause, you can do it, but those changes aren't reflected in MV's source table. Moreover, as soon as you refresh the MV, changes you've made will be lost.
Advanced replication covers it, but Oracle says that it is deprecated in 12cR1.
There's a walkthrough on Vinayaga Consultancy's blog, Updatable Materialized View, based on Oracle 11.2 (source) and 10.2 (target database) so - have a look. It isn't that trivial at all.

When indexed view updated

I create a indexed view View1 on Table1 and Table2 and have instead of trigger and after trigger on Table1 that use of View1. It seem that data of View1 not change when I use this view on instead of trigger and after trigger. But I want to use View1 with new data when use this view on after trigger. How can I do it. It should be noted that I use with Noexpand hint when use indexed view (when don't use with noexpand hint in SQL Server 2008 R2 act this indexed view such as no indexed view).
The indexed view is updated after all triggers on the base tables are executed. You can see that in the query plan. There will be only one clustered index update on the view.
However, you can create INSTEAD OF triggers on the view and then make all your operations on the indexed view. However,there are some restrictions when updating/inserting/deleting through an updateable view. You can read about them here.
Note that views allow only INSTEAD OF triggers, not AFTER too.
The most important thing to know about updating indexed views is that any modifications, including UPDATE, INSERT, and DELETE statements, must reference columns from only one base table.