how to convert materialized view into normal view - sql

I am using Oracle 11g EE and created one Materialized view for a complex query.
But as customer is using Standard edition and it doesn't support Materialized view.
So I need to convert materialized view into a normal view.
Along with this conversion I also need to make sure performance of a query.
When I treid to execute a query for the view independently, it takes around 20 mins which is too much time.
All my tables are indexed.
Any sort of help would be appreciated !!

I don't currently have access to an oracle database to test this, but if you get the DDL of the mview, and remove the word materialized along with the mview related options:
select dbms_metadata.get_ddl('MATERIALIZED_VIEW', 'MVIEW_NAME') from dual;
You should be able to create a normal view from the resulting modified statement.
As for performance, make sure you are indexing the right things, and using the right type of indexes. Make sure statistics are up to date, and finally run explain plan on the view query. The topic of interpreting and optimizing execution plans is deep - start here:
https://docs.oracle.com/cd/B10501_01/server.920/a96533/ex_plan.htm

Related

How "CREATE VIEW" works?

I'm a newbie in here. I had a problem that need your help.
Here is my context: I have 1 table that contains 100 mil data rows. I need to build reports from this table. I use Power BI, using direct import, and write SQL statements in Power BI. When the data loaded to Power BI, it reduced to 20 mil rows (cause I used GROUP BY in SQL statement). But the performance of Power BI is really terrible. In my opinion, Power BI had to run the query statement, and then visualize data, so its performance is bad.
Here is my solution: I'm going to CREATE VIEW (using GROUP BY statement) in my database. So that, the run query workload is no longer belongs to Power BI. My database will take responsibility for the executive SQL statement. And Power BI just only need to visualize data, so the performance of Power BI will be better.
Here are my questions:
1 - Does my solution work? :)))
2 - IF my solution work, my database just needs 1 time in running CREATE VIEW statement, and no need to run it anymore in the future, right?
3- If my solution work, the SQL running workload will move from Power BI to my database, right?
Thank you in advance.
When you use Import mode, then your Database is query once (at refresh time), but the view still need to make aggregation and there is no difference between select from view vs select with the group by (the view is only a nice packed query, better to materialize view or populate standard Table with the daily job);
It's a good idea to remove unused columns and rows, older than X (also aggregate if possible).
Consider using Incremental refresh to shorted your load.
https://learn.microsoft.com/en-us/power-bi/connect-data/incremental-refresh-overview
Incremental refresh is supported for Power BI Premium, Premium per user, Power BI Pro, and Power BI Embedded datasets.
I have no idea about powerBI but if you use view it executes the query in view every call. You can try materialized view instead of view. But be aware materialized view has the snapshot of data when it created or refresed time.
as an example the view MY_MATERIALIZED_VIEW is refreshing every day.
create materialized view MY_MATERIALIZED_VIEW
build immediate
refresh force
on demand
start with sysdate next sysdate + 1
as
....query

Moving Data from SQL Server to Excel, Views or Query?

I have an Excel spreadsheet that pulls data from a view (that's pulling from another view) in SQL Server, this was created by someone other than myself. Due to recent changes in how we are storing data in SQL Server, the views no longer actively reflect the data needed.
The current Excel spreadsheet use a command to simply pull the rows from the view, would it make more sense to simply use a query to gather the data from the necessary tables? Is there any advantages to using the views over a regular query?
There is no security being enforced in regards to the view as well, the connection is using an admin user.
When we talk about regular views, the only advantage over query is that I see a shorter expression, i.e. 'select * from view' will be easier to type and edit in MS Query than 'select * from ... join ... join ... where ...' etc. If we are talking about indexed views, then they can greatly improve performance

Autogenerate sql query from the Graphical calculation view?

I am trying to test a graphical calculation view in SAP- HANA but I can't edit it due to some production constraints. Is there any way to I Can get the query equivalent of the Calculation view without altering the data at the same time?
No, there is no direct calcview - SQL statement conversion available
Why don't you simply copy the calcview in question and modify the copy?

SQL View optimisation

I have inherited an existing system and am trying to figure out a few things.
The system does a
SELECT * FROM v_myView WHERE mvViewCol = 'someValue'
and v_myView performs summation of Table1 based on myViewCol
Does SQL Server 2005 optimize the query or will summation always occur across the entire Table1?
I understand that I could use a parameterized view but don't want to go changing things unnecessarily.
Cheers
Geoff
Views have no runtime cost at all. They are always inlined into the surrounding query as if you had pasted the view definition as text. They would be impractical to use otherwise.
Does SQL Server (2005) optimize the query or will summation always occur across the entire Table1.
It will be optimized.
This is a complicated question. I think the best explanation is here. I do wish Microsoft documentation were a little clearer on this point.
When a view is created, the query is parsed. This ensures that it is correct.
The execution plan is determined the first time the query is run (to a close approximation). This execution plan then remains in the plan cache for subsequent calls. So, if you have an index on the appropriate columns and the first execution has a where clause that would use the index, then subsequent calls will also use the index.
I say to a close approximation, because it is really the first time that a view is called when the plan is not in the plan cache. Certain changes to the database will flush the plan, as will restarting the server.
So, if you only access the view with the where clause, then subsequent uses of the view will be optimized for that purpose.
SQL Server 2005 will optimize the view each time it is referenced in a query : http://technet.microsoft.com/en-us/library/cc917715.aspx
"After view expansion, the SQL Server query optimizer compiles a single execution plan for the executing query."
I don't have 2005 installed but it will operate similiar to 2008R2 - To view the Query Optimization Plan, right click in the query window and select "Display Estimated Execution Plan" for more info and to spot any bottlenecks.
In the Query menu option, there is "Analyse Query in Database Tuning Advisor" that may also be of benefit to you.

Does MySQL have an equivalent of SQL Server "indexed views"?

Does MySQL have an equalavent to SQL Servers "indexed view" functionality?
Is a view faster than a simple query?
What I'm specifically looking for is a way for MySQL to create a "view" that will return results faster than simply performing the underline view's query/sql.
An Indexed View is SQL Server terminology for a materialized view, which MySQL does not support.
You can either:
re-create a temporary table, populated with the desired columns, at a given interval
use an actual table, populated and indexed though again - there'd have to be a process to keep the data and indexes current