Showing posts with label Perf_Tuning_DB. Show all posts
Showing posts with label Perf_Tuning_DB. Show all posts

Jul 12, 2016

Partitions Oracle

list partition

List partitioning is a partitioning technique where you specify a list of discrete
values for the partitioning key in the description for each partition.
CREATE TABLE myemp_work (
       emp#   NUMBER PRIMARY KEY,
       ename    VARCHAR2(30),
       salary   NUMBER(8,2),
       deptno   NUMBER)
  PARTITION BY LIST (deptno) ( 
       PARTITION p10 VALUES (10),
       PARTITION p20 VALUES (20),
       PARTITION p30 VALUES (30,40));
                  
range partition                         can be done on varchar, number and date fields
Range partitioning is a partitioning technique where ranges of data is stored separately in different sub-tables.
CREATE TABLE emp (
   empno NUMBER(4),
   ename VARCHAR2(30),
   sal   NUMBER
)
PARTITION BY RANGE(empno) (
  partition e1 values less than (1000)     tablespace ts1,
  partition e2 values less than (2000)     tablespace ts2,
  partition e3 values less than (MAXVALUE) tablespace ts3
);

hash partition this can be done on unique value columns
Hash partitioning is a partitioning technique where a hash key is used to distribute rows evenly across the different partitions (sub-tables).
This is typically used where ranges aren't appropriate, i.e. employee number, productID, etc.
create table emp2 (
   empno number(4),
   ename varchar2(30),
   sal   number
)
partition by hash(empno) (
  partition e1 tablespace emp1,
  partition e2 tablespace emp2,
  partition e3 tablespace emp3,
  partition e4 tablespace emp4
);

sub partition: Partitions created within partitions. They are just partitions themselves and there is nothing special about them.

Advantages of using partitions in table
1. Smaller and more manageable pieces of data (partitions).
2. Reduced recovery time.
3. Failure impact is less.
4. Export/Import can be done at the partition level.
5. Faster access of data.
6. Partitions work independent of the other partitions.
7. Very easy to use.


Ref: Source

Oct 11, 2012

Tips to Performance tuning in all db's


JOIN or  Correlated subquery with exists clause, which one is better
select *
from ContactInformation c
where exists (select * from Department d where d.Id = c.DepartmentId )

select *
from ContactInformation c
inner join Department d on c.DepartmentId = d.Id 

Generally, the EXISTS clause because you may need DISTINCT for a JOIN for it to give the expected output. For example, if you have multiple Department rows for a Contact Information row.

In your example above, the SELECT *:

means different output too so they are not actually equivalent
less chance of a index being used because you are pulling all columns out
Saying that, even with a limited column list, they will give the same plan: until you need DISTINCT... which is why I say "EXISTS"

Difference between in IN and EXISTS in Teradata SQL
Performance wise both should be same with less no of records.
If no of records will be more, EXISTS is faster than IN.
Mostly IN is used in case of subqueries and EXISTS is used in case of correlated subqueries.

Difference between subquery and correlated subquery in SQL?
Subquery :- The inner query is executed only once The inner query will get executed first and the output of the inner query used by the outer query.The inner query is not dependent on outer query.

Eg:-  SELECT cust_name, dept_no FROM Customer WHERE cust_name IN (SELECT cust_name FROM Customer);

Correlated sub query:-The outer query will get executed first and for every row of outer query, inner query will get executed. So the inner query will get executed as many times as number of rows in result of the outer query. The outer query output can use the inner query output for comparison. This means inner query and outer query dependent on each other.

Eg:- SELECT cust_name,dept_id FROM Cust
WHERE cust_name in (SELECT cust_name FROM dept WHERE cust.dept_id=dept.dept_id);

Oracle: Hints based on perf


/*+ INDEX(e1 ENC_REG_PK_IDX)
           USE_MERGE(ag) FULL(ag) */

--/*+ PARALLEL(6) */  -222 secs.

/*+ INDEX_COMBINE(er ENC_REG_PK_IDX ENC_REG_ACCT_REC_PK_IDX ENC_PMT_ADJ_PK_IDX ) */  --196

/*+ INDEX_FFS(er ENC_REG_PK_IDX) */  ---232

/*+ STAR_TRANSFORMATION */ ---218