Oracle SQL performance with database links - db link

What are some of the performance issues when running SQL across a database link (dblink)?

  • Pull vs. Push - In general, performance can be faster if you "pull" the data (calling the remote table from the master instance), as opposed to a "push" where you perform the join on the remote table.  This is especially true of you have a large sort, because the rows may be transferred to the remote host for sorting, and then back again afterwards.
  • driving_site hint - The driving site hint forces query execution to be done at a different site than the initiating instance.  This is done when the remote table is much larger than the local table and you want the work (join, sorting) done remotely to save the back-and-forth network traffic.  n this example, we use thedriving_site hint to force the "work" to be done on the site where the huge table resides:
select /*+DRIVING_SITE(h)*/ 
  tiny_table        t, 
  huge_table@remote h
   t.deptno = h.deptno;

Note:  The driving_site hint will not work with CTAS (create table as select) and with create materialized view syntax because they are DDL and these operations must take place on the original instance.

  • Views - Some recommend creating a view on the remote site referencing the local tables and calling the remote table via the local view. 
create view local_cust as select * from cust@remote;

You can get the same effect by using an inline view:

FROM (SELECT stuff FROM emp@remote) a
  • Sorting - If your SQL performs a sort, be aware that the sort will be performed on the LOCAL database.  This is one reason why it's bad to use a "push" approach, because the rows will traverse back-and-forth. 

  • Parallelism - Parallel query across a database link can be quite complex.   In a distributed environment, pieces of a table may reside on many remote servers.  For example, assume that we have a distributed architecture where local customer tables are kept on each instance.  You could access all of the remote rows in a single query, using inter-instance parallel execution.  In this example, the query is executed from the north_carolina instance, accessing two remote instances in-parallel:
select customer_name, sum(purchase_amount) from sales
   select customer_name, sum(purchase_amount) from sales@san_francisco
   select customer_name, sum(purchase_amount) from sales@new_york
   group by
  • In this case the north_carolina instance drives the distributed parallel query and it is the north_carolina instance that must gather and sort the result set.

Alberto Dell'Era notes this tip for distributed query parallelism:

"I had some problems myself while mixing db-links and parallel operations; i solved them perfectly by creating a view at the remote site with the same text as the query, and then performing a "select *" from the view. "

Also, note that there are many hidden parameters that influence OPQ performance (always consult Oracle technical support before changing an undocumented parameter)

NAME                                VALUE
----------------------------------- ---------------------_parallel_adaptive_max_users        1
_parallel_default_max_instances     1
_parallel_execution_message_align   FALSE
_parallel_fake_class_pct            0
_parallel_load_bal_unit             0
_parallel_load_balancing            TRUE
_parallel_min_message_pool          64560
_parallel_recovery_stopat           32767
_parallel_server_idle_time          5
_parallel_server_sleep_time         10
_parallel_txn_global                FALSE
_parallelism_cost_fudge_factor      350

Monitoring parallel query for remote distributed queries is also challenging.

  • Network -  Generally, the limiting factor in SQL performance of a distributed query (over a db-link) is the speed of the network (make sure that you have a high-speed network with proper SDU), but there are other issues:
    • tnsnames.ora - Some recommend a separate listener and a larger value for SDU to accommodate jumbo Ethernet frames.

"By using a separate listener for the gigabit network with a larger SDU - you can better exploit jumbo Ethernet frames. beware - interoperability just plain sucks.

Credit :: Tips by Burleson Consulting)


Tableau - Magic Quadrant for Business Intelligence and Analytics

Gartner Magic Quadrant for Business Intelligence and Analytics

Gartner Magic Quadrant for Business Intelligence and Analytics

Tableau's highly intuitive, visual-based data discovery, dashboarding, and data mashup capabilities have transformed business users' expectations about what they can discover in data and share without extensive skills or training with a BI platform.


  • Tableau offers an intuitive, visual-based interactive data exploration experience that customers rate highly, and that competitors, large and small, try to imitate.
  • Core differentiator — making a range of types of analysis (from simple to complex) accessible and easy for the ordinary business user, whom Tableau effectively transforms into a "data superhero." Enabling business users to perform more complex types of analysis without extensive skills or IT assistance 
  •  A high percentage of users also said they chose its platform because of its low cost to implement; Tableau customers reported one of the lowest implementation costs per user of any vendor in the survey. 


  • Although Tableau's average user count continues to grow and was above the market average in this year's customer survey, its products are often used to complement an existing BI platform standard; only 42% of its customers considered it as their BI standard.
  • New shoots of innovation relating to the automation of advanced analytics are emerging from vendors like IBM (Watson Analytics), which could threaten the dominance of the Tableau-based data discovery paradigm. Although these efforts have had limited success to date, the stakes are high for the incumbent vendors that are losing new license purchases to data discovery vendors such as Tableau.
  • Gartner's inquiries reveal that customers often view Tableau as inflexible in contract negotiations and complain that its 25% annual maintenance fee is higher than those of most other vendors.
1 Comment

Automatic Bulk Formatting W/Toad

We write code once, but read it many times. PL/SQL is a functional language which is very readable. We should make every effort to make the code cleaner and maintainable.

We have Oracle code in the source control repository that does not meet standard formatting practice. Also in many cases developers do not have access to Toad, or choose not to take advantage of Toad for-matter.

How do we automate the formatting of Code in Bulk to meet the standards ?

The Solution : Toad for Oracle’s Automation Designer.

The idea is to create an App/program in Toad with instructions to format files in a specific folder. We can then run this App in Toad or through command-line.

I have detailed steps below on how to create an app using Toad, that takes files in a folder and automatically format them, then call this action from the command-line so it can be built into your existing build automation scripts.The process to import the TOAD settings are provided on page 4.

Step 1: Create a new App

I have created a new folder called ‘GWP Coding Standard’ in the AppsDesigner GUI. This is an optional step, by default your new apps will appear in the ‘Default’ folder.

Step 2: Formatting files

(Just read through Step 2, no need to take any action)

It is very easy to tell Toad to format a specific file. I can simply choose the ‘Format Files’ action from the ‘Utilities’ page and supply the file name(s).

When you double-click on the ‘Format Files’ action in my app action list, you will see the required inputs and properties for the format option.

Unfortunately this method requires that you know the file names in advance. If you are receiving a directory of files to be formatted, you do not want to explicitly input each file name every time you want to run the app. So, the brilliant minds behind Toad have given us the ‘Folder Iterator’ action.

Step 3: Create a Folder Iterator Action and point it to our input directory.

Go the “Control” Tab and click on the “Folder Iterator”.

Once you have that action in your action list, open it’s properties dialog.

Pay attention to the ‘recursive’ option. If your input directory contains sub-folders, you will want to enable this. That will cause Toad to open each folder and recursively work with each file. I have chosen the ‘*.sql’ file type, but you could have just as easily gone with just ‘*.prc’ files or all file type “.”.

Step 4: Add the Format Files Action

Instead of using the Format Files action by itself, we are going to add this as a sub-action( see red circle below) to the above ‘Folder Iterator’ action.

Click on “Add Variable “ to get the select variable dialog. Select the variable “Folder Iterator1” created in Step 3.

Step 5: Test the app

Simply hit the ‘Run selected apps’ button from the AppDesigner toolbar. Any error messages will get logged to the bottom ‘Single Run’ panel.

Step 6: Run via command-line

To execute our app from the command-line, we simply need to know the name of our app.

Import App from File

Simply download the App (txt file) to a known location on your desktop. Open Toad and launch Automation Designer. Click the “Import App from File” button to import the App with its Actions into your window. You will have to change some of the properties (right click the Action and select Properties) so that this App works in your environment or you can simply read it so you get the idea.

Source Control and formatted code

When we check-in the formatted code, that must be the ONLY change checked-in into the source control. We must remember that formatting the code eliminates (or at least greatly reduces) the ability to track previous changes.

Process to import TOAD format settings

  1. Go to View → Toad Options
  2. Go to left panel and click on “Formatter”. You can load a new format option file (.opt) using the button.

Oracle Coding Best Practices

This document defines a list of standards and guidelines that will be used when submitting PL/SQL Components. Good standards do not constrain the creativity of designers and developers, but rather encourage the development of best practices.  

Read More

Speed Oracle SQL with Temporary Tables (GTT)

The effective use of temporary tables while doing huge batch process can boost performance. The concept is to store intermediate data while performing huge processing in temporary tables. Temporary table store data in-memory that results in better and stable SQL plan for complex summarization activities.

#GTT #SQL Performance #Oracle

Read More

SQL Profiles Vs SQL Plan Baselines?

What's difference between SQL profiles and SQL plan baselines. But first let's briefly recap each feature.

Programmers add hints to SQL query to give direction to the Optimizer. Both SQL Profiles and Baselines are nothing but collections of stored hints that “attach” to their target SQLs.

Both SQL Profiles and SPM Baselines are designed to deal with the same problem "Optimizer sometimes produces a very inefficient execution plan", and they are both doing it by essentially abandoning the idea that “all SQLs are created equal”. Instead, another idea is put forward  “Some SQLs are special and deserve individual treatment”.

The way they are implemented, both SQL Profiles and SPM Baselines are:

  • External objects that contain additional “magic” information for the optimizer
  • Attached to individual SQLs and influence them only
  • Built by actually running the SQL and using feedback from runtime engine

What is the “magic” contents that profiles and baselines use to influence SQL execution plans ?

Based on hint contents, there are some major differences in SQL influence “mechanics” between SQL Profiles and SPM Baselines:

  • SQL Profiles (“Soft power”) are mostly ADVISORS that work with the Optimizer making its estimations more precise
  • SPM Baselines (“Hard Power”) on the other hand are ENFORCERS. They completely ignore the Optimizer and simply tell the runtime engine what to do

Is there any difference in purpose ?

Now that we’ve seen the actual contents of both SQL Profiles and SPM Baselines, let’s talk about their purpose.

SQL Profiles were designed to correct Optimizer behavior when underlying data do not fit anymore into its statistical (and simplistic) world view. Their goal is to create the absolute best execution plan for the SQL by giving the very precise data to the optimizer. In other words, SQL Profiles are all about “ON THE SPOT” SQL PERFORMANCE.

Baselines, on the other hand are different. They were designed to prevent execution plans from changing uncontrollably and their goal is to only allow execution plans that were proven to be efficient. In other words, SPM Baselines are all about LONG TERM STABILITY.

Baselines know what plan they are trying recreate and SQL Profiles do not. SQL Profiles will blindly apply any hints it has and what you get is what you get. Baselines will apply the hints and if the optimizer gets the plan it was expecting, it uses the plan. If it doesn't come up with the expected plan, the hints are thrown away and the optimizer tries again (possibly with the hints from another accepted Baseline).

Profiles have a “force matching” capability that allows them to be applied to multiple statements that differ only in the values of literals. Think of it as a just in time cursor sharing feature. Baselines do not have this ability to act on multiple statements.

Can Baseline be disregarded?

Baselines can be rejected in the underlying objects (“indexes”) were missing. Baselines can be disregarded, even without such extreme conditions as a specified index having been removed. The reason for this is that Baselines attempt to apply enough hints to limit the choices the optimizer has to a single plan, but there are situations where the set of hints is not sufficient to actually force the desired plan. What I mean is that the hints will eliminate virtually all possibility, but there still may be a few that are valid and so it’s possible to get a different plan. In fact, there are situations where the act of creating a Baseline causes the plan to change. This is clearly not intended behavior, but it can happen.  At any rate, in these cases where the optimizer arrives at a different plan than was expected, the optimizer uses a plan generated completely without the hints (or possible picks another accepted Baseline and applies it’s hints). This behavior is very different from SQL Profiles which blindly apply the hints.

Note: SQL Profiles can also be created manually with the same set of hints that would be used in a Baseline and there is a MOS note regarding how to do this. 

SQL query to get SPM baseline.

SQL> select count(*) from dba_sql_plan_baselines where parsing_schema_name='$1';




Oracle Temporary tables - Features and Effective Use

Oracle Database temporary tables hold data that exists only for the duration of a transaction or session. Data in a temporary table is private to the session, which means that each session can only see and modify its own data.Temporary tables are useful in applications where a result set must be buffered.

Read More

How To Identify Time Of Last Row Update

Identifying the time a row was last updated used to involve either adding a column to the table itself and coding the application to update it with a date and time value, or switching on auditing with its performance overheads, or using Logminer to trawl through old archive logs.

TAGS : Girish, Shine


Read More

Oracle GoldenGate Vs Informatica PWX CDC for Oracle

We will explore the change data capture(CDC) integration suite from Oracle and Informatica, the two data integration leaders from the Gartner Magic Quadrant. The two leaders will be compared on; modes of interaction (CDC, bulk event), data transformation capabilities, design and development and  architecture.

#Oracle #CDC

Read More

Advantages of Packages

Packages offer several advantages: modularity, easier application design, information hiding, added functionality, and better performance. The blog explores the advantages of using packages.

Read More