Oracle TOAD and Materialised View - oracle

i am new to oracle.Already there is a store procedure which fetches data from many tables.Due to performance issue,i need to modify it.So i want to know about materialised view (since,i already searched it in net,but i am not able to understand it).can anyone explain the features of it?
Also,i am using TOAD for oracle.Can someone suggest me any materials(book,websites etc.) to learn?

I'll take the Toad portion - you can get a ton of great help online for free at ToadWorld.com. I have a 35 page free tutorial there as well link text

Materialized View is covered in the documentation (eg here).
They don't make anything magically run faster. They move the performance hit (eg refresh the view at midnight and your procedure may run faster at 9am) but possibly at the expense of being 'up-to-date'. Or you could have REFRESH ON COMMIT MVs which can be more up to date, but maybe at the expense of concurrency and are also 'time shifting' work to when inserts/updates are done rather than queries.
MVs would be a long way down the list of things I'd consider for fixing a problem in a specific stored procedure.

Related

ORACLE - Which is better to generate a large resultset of records, View, SP, or Function

I recently working with Oracle database to generate some reports. What I need is to get result sets of specific records (only SELECT statement), sometimes are large records, to be used for generating the report in excel file.
At first, the reports are queried in Views but some of them are slow (have some complex subqueries). I was asked to increase the performance and also fixed some field mapping. I also want to tidy things up, because when I query against View, I must specifically call the right column name. I want to separate the data works into database, and the web app just for passing parameters and call the right result set.
I'm new to Oracle, so which is better to do this kind of task? Using SP or Function? or in what condition that maybe View is better?
Makes no difference whether you compile your SQL in a view, SP or function. It is the SQL itself that matters.
As long as you are able to meet your requirements with the views they should be a good option. If you intend to break-up your queries into multiple ones for achieving better performance then you should go for stored procedures. If you decide to go for stored procedure then it would be advisable to create a package and bundle all the stored procedures together in the package. If your problem is performance then there may not be a silver bullet solution for the same. You will have to work on your queries and design for the same.
If the problem is performance due to complex SELECT query (queries), you can consider tuning the queries. Often you will find queries written 15-20 years ago, which do not use functionality and techniques that were introduced by Oracle in more recent versions (even if the organization spent the big bucks to buy the more recent versions - making it into a waste of money). Honestly, that may be too much of a task for you if you are new at Oracle; also, some slow queries may have been written by people just like you, many years ago - before they had a chance to learn a lot about Oracle and have experience with it.
Another thing, if the reports don't need to use the absolute current state of the underlying tables (for example, if "what was in the tables at the end of the business day yesterday" is acceptable), you can create a materialized view. It will not work any faster than a regular view, but it can run overnight (say), or every six hours, or whatever - so that the further reporting processing from there will not have to wait for the queries to complete. This is one of the main uses of materialized views.
Good luck!

Creating a non-materialized view takes a lot of Time and CPU in oracle

I'm working on migrating application from Access to Oracle and have faced with a strange issue . So we have a regular oracle schema - nothing fancy. on the top of that schema I created a number of views - approximately 15. These views use each other and dependency tree can be deep - I'd say up to 6-8 levels.
So now I faced with an issue when I cannot create another view - CPU at oracle servers goes to 50% when I execute 'create or replace view' statement and it takes forever. Views are right now in such a state that selection data from these views may take time, but the issue appears in 'create' statement. I'm not using 'select * ...' in the views and the problematic view depends just on two others.
I'm using Oracle 10g Enterprise v 10.2
In SQL Server I'm familiar with Profiler and would do a trace, view schema locks, but I don't know Oracle that much.
Will appreciate any hints. Thank you.
Views referencing views referencing views strikes me as highly unnecessary. I know we're all supposed to be in favour of "don't repeat yourself" but DRY is a guideline, not a cast-iron rule. It's certainly not intended to be applied so compactly in a database context that nothing compiles.
So try separating out all the views, so that each one references only tables in the FROM clause. That should solve your problem and allow you to make progress with your code.
You can always review the situation later. The neat thing about a view is that it is just an interface. If you subsequnetly want to refactor some views, to replace tables with views than you will be able to, with the minimum of inconvenience (unless you re-introduce the compilation hang).

Doesn't Read-Only make a difference for SQL Server?

I’ve been tasked with optimizing a rather nasty stored procedure in a legacy system. It’s a database dedicated to search, and a new copy is being generate every day, with a lot of complex joins being de-normalized. No writes are being performed, only SELECTs, so I figured some easy improvements could be made by making the whole database read-only and changing the recovery model to “Simple”.
Much to my surprise, this didn’t help – at all! The stored procedure still takes the same amount of time of complete. If fact, I’m so surprised that I figured I did it wrong!
My questions:
Do I need to do anything other than setting “Database read-only” to “true”?
Am I wrong to expect significant performance improvement by making the database read-only?
Same for the recovery model: Shouldn’t “Simple” have some noticeable impact?
Are there other similar database-wide configurations that can improve performance in this scenario?
The stored procedure is huge, with temporary tables, 40+ tables joined in 20+ queries. But I’d like to optimize the database itself before I edit this proc.
Since no writes are performed by your SP, there is no reason to expect noticable performance improvement from changing recovery model and read-write mode.
As others mentioned, you should look into the query plan and optimize your queries.
Another hint: indexes in the database might get fragmented while the database is filled up. Since the data is not going to be modified any more, it might help to rebuild all the indexes with fillfactor 100 - this might help to get rid of fragmentation and to compact data.
Call this for each table in the database: ALTER INDEX ALL ON table_name REBUILD WITH (FILLFACTOR = 100).
Generally, I won't expect much of performance improvement from this, but it depends on the particular database.
Speaking of query optimization, there are very useful features in SQL Server 2005 and later: Execution Related and Index-Related Dynamic Management Views. In particular, sys.dm_exec_query_stats and missing indexes are of interest.
These give you almost the same information as Tuning Advisor, but using you real-life workload, so you don't need to simulate it and feed to the Advisor.
Have you tried using the Database Engine Tuning Advisor included in SQL Server? It will analyze your query and suggest new indexes that will improve the performance of the query. Some of them will be good, some will be bad (for example, I've seen it suggest adding every column in a table to an index, sometimes like 30 of them!), so I don't follow it blindly. Generally I'll add a few indexes and then retest, to find the suggestions that are the most important. I've used it to optimize many queries that I thought I had properly indexed, only to find I could get a lot more performance out of them.
I had a similar setup, large stored procedures with lots of large temp tables.
Our problem was that the joins with and between the temp tables was very slow.
I recommend that you look at your execution plan and try to add relevant indexes to the temp tables too if you have not already.

Creating view & performance in the database.,

IF a create thousands of view, Does it hamper the database performance. I mean is there any problem with creating thousands of view in oracle. Please explain as I am new in this area...I am using oracle...
The simple existence of these views shouldn't harm performance at all. However, once those views start being used it's possible that there will be some negative performance impact. Oracle tries to "remember" the plan for each statement that it sees, but it compares statements by comparing the source code (the SQL). Your thousands of views will all be named differently since you can't have multiple views with the same name, and thus each time one of them is used Oracle is going to have to do a full parse of the SQL, even if it's something as basic as
SELECT * FROM VIEW_1;
and
SELECT * FROM VIEW_2;
All these re-parses will certainly take some time.
What's different about each of these views? I think it might be a good idea to step back and consider other possibilities. Questions I'd ask include
What is to be accomplished here?
Why are thousands of different views needed?
Is there some other way to accomplish what needs to be done without creating all these views?
I don't know the answers to 1 and 2, but I'm reasonably sure that the answer to #3 is "Yes".
Good luck.
Oracle views are an encapsulation of a
complex query and must be used with
care. Here are the key facts to
remember:
Views are not intended to improve SQL
performance. When you need to
encapsulate SQL, you should place it
inside a stored procedure rather than
use a view. Views hide the complexity
of the underlying query, making it
easier for inexperienced programmers
and end users to formulate queries.
Views can be used to tune queries with
hints, provided that the view is
always used in the proper context.
source: Guard against performance issues when using Oracle hints and views
View is as heavy to run as the select that creates it but Oracle loads balance and single select can't harm the DB. If you have thousands concurrent selects going then you might have a problem. The amount of views is not important but how heavy they are and how much you use them.
You would actually need to show the views code and tell what you are actually trying to do.
View should not affect performance, if optimizer is smart enough. I remember cases with other DB engines when Views do harm performance. As in many performance cases - I suggest to measure your particular case.

Any issues with join hints in a SQL Server 2000 view?

I have some ad-hoc reporting users hitting some SQL Server views. Occasionally the read locks taken by these users for particularly lengthy queries causes trouble elsewhere in the system.
I am considering adding some strategic with(nolock) hints to the views but wanted to know if there are any gotchas associated with hints in views.
Please ignore the obvious issues with letting users run queries this close to the SQL metal :).
Also, I know that nolock hints are an advanced feature not to be used lightly and I am well aware that they introduce fun things like dirty reads. Finally, if you're thinking that read_committed_snapshot makes sense here, I must sadly say that it's not available for 2000.
There is a potential for the report to show an inconsistent view of data. That kind of thing is rare, though.
Still, a better strategy is to use replication to create a completely separate reports database.

Resources