Monday, March 5, 2018

Difference between Execution Plan and Explain Plan

An explain plan predicts how Oracle will process your query, where as an execution plan describes the steps it actually took.

The main difference between the AUTOTRACE and EXPLAIN PLAN commands in Oracle is that AUTOTRACE actually executes the query (in the way TRACE does) and automatically queries the plan table, whereas EXPLAIN PLAN does neither. The AUTOTRACE command generates similar information, as shown in the next listing. To use AUTOTRACE, the user must possess the PLUSTRACE role (by running plustrce.sql, which is usually located in the ORACLE_HOME/sqlplus/admin directory).

the autotrace statistics reported however are FACTS, after executing the statement, not guesses, not part of optimization. 

So, autotrace used explain plan to show the plan that probably, likely will be used and autotrace shows the ACTUAL number of resources expended to execute the query. 

According to Tom's suggestion:
If you understand the small number of times it could be misleading, you can use it to judge what will probably happen. It shows the GUESS, we compare the guess to reality to understand why a bad plan is generated. 


We always want the reality, and the plan - reality(Execution Plan/ Auto trace) shows us what actually happened, the plan is the guess and as long as the explain plan steps match the actual - we can use that to help understand what the optimizer was thinking. As a person tuning sql, that is very useful. But by itself, the plan is "interesting" but must be considered for what it is - "probably what might happen" 

Top tip: If someone asks  for “the plan” they’re usually looking for one of the execution variety. I.e. what really happened. We should provide the execution plan in that case.

Sunday, February 25, 2018

Installing the latest Version of R in Ubuntu

By executing the below commands we can install R in ubuntu. 

sudo apt-get --purge remove r-base
sudo apt-get --purge remove r-base-dev

This install the default version of R. If we want to install the latest version of R, we can follow as:
Uninstalling the previous version of R


sudo apt-get --purge remove r-base
sudo apt-get --purge remove r-base-dev
sudo apt-get --purge remove r-base-core


After that to install R:

sudo add-apt-repository "deb http://cran.rstudio.com/bin/linux/ubuntu $(lsb_release -sc)/"


Then we will have to execute the below commands:

sudo apt-key adv --keyserver keyserver.ubuntu.com --recv-keys E084DAB9
sudo add-apt-repository ppa:marutter/rdev
sudo apt-get update
sudo apt-get upgrade
sudo apt-get install r-base

Reinstalling R in Ubuntu

For the case if we want to reinstall R on our ubuntu, we have to uninstall R at first. To do so, we can use the bwlow commands:


sudo apt-get --purge remove r-base
sudo apt-get --purge remove r-base-dev


As r-base package is just a metapackage that also installs r-base-core internally. We will have to remove r-base-core to remove fully.

sudo apt-get --purge remove r-base-core

After removing all the packge we will have to use below command to install the R again:


sudo apt-get install r-base
sudo apt-get install r-base-dev

Wednesday, December 27, 2017

Problem to mount NFS : mount: wrong fs type, bad option, bad superblock

Sometime, we may get error as  mount: wrong fs type, bad option, bad superblock while trying to mount NFS file in ubuntu. For my case, i faced the problem showing the error as:


The reason behind it that for several filesystems (e.g. nfs, cifs) we might need a /sbin/mount. helper program.
As we are trying to mount NFS. The /sbin/mount.nfs helper program is provided by nfs-common. We can install it with:

sudo apt-get update
sudo apt install nfs-common

On the other hand, if we are trying to mount CIFS, the helper program is provided by cifs-utils. We can install it using below command:

sudo apt install cifs-utils


Then we can mount our target as:
We will have to create a directory where to mount the nfs,

sudo mount :/ /

Thursday, December 21, 2017

Get elapsed time for an individual command

In sqlplus, to see the elapsed time for an individual query, we can use the "set timing on" command.

SQL> set timing on;
SQL> select surname from personal_details where firstname='udvas';

Elapsed: 00:00:02.52

Again, the "set timing on" command is a SQL*Plus command, but we can measure run time for Oracle SQL with a variety of Oracle tools.

Sometimes when working on SQL command optimizations, all that is desired is a rough timing estimate; namely, the SQL*Plus client elapsed execution time, or simple clock time. Often that simple metric is sufficient for some very basic tuning needs. SQL*Plus has a built-in capability to do exactly this - it is the SET TIMING  command. It essentially records the clock time before and after the SQL command execution, then displays the run time difference.

This commands works for the single command.