WHERE E.DEPT_ID = D.DEPT_ID
WHERE E.DEPT_ID = D.DEPT_ID
Blog Owner
Labels
- Android (3)
- Database Concepts (2)
- Gujarati - હાસ્ય લેખન (4)
- Jainism (4)
- jasper report (6)
- Java Development (7)
- Oracle Query (4)
- Tips n Tricks (4)
- Useful Technology (7)
- XML Processing Using JAVA (2)
Facebook Badge
Facebook Badge
Blog Archive
Followers
Give away of the day
Powered by Blogger.
Custom Search
Posted by
vivek shah
Wednesday, October 20, 2010
Often you may be faced with a requirement to optimize a sql query(increase query running time) to be executed in oracle database. Query Optmization in general is a huge topic to discuss. Let me provide some basic steps to be followed while optimizing a sql query.
1. If the query has only one table and certain where conditions, then try to index the columns given in the where condition. By default primary key columns are indexed. Then try to reorder the set of where conditions based on number of rows for the column values in descending order.
2. If the query contains more than one table (joins), first try to order the tables in descending order (number of rows) in the 'from' clause. Then try to reorder the set of where conditions based on number of rows for the column values in descending order. Try executing the sql query in TOAD to get the explain plan and then find the tables which are taking more time to retrieve rows in explain plan and index the required columns in those tables.
3. Try using sql hints to make the query execution faster. Let see some of the common hints available in oracle
ORDERED - This hint will execute the query in the same order of tables.
SELECT /*+ ORDERED */ FROM employee e
INDEX(tablename indexname) - this hint will force the system to use the particular index while executing the query
SELECT /*+ index(e emp_pk) */ FROM employee e
USE_NL(table1, table2) - this hint will use nested loop joins to join table1 and table2.
SELECT /*+USE_NL(a,sn) */ FROM employee e,DEPARTMENT D
We can also use more than one hint in a single query as follows.
SELECT /*+ORDERED USE_NL(a,sn) */ FROM employee e,DEPARTMENT D
Oracle DBMS will optimize every query it receives for execution. But if you are not satisfied with the default optimization done and query execution time you can follow the above steps to optimize your query.
Labels:
Oracle Query
Subscribe to:
Post Comments (Atom)