Presentation is loading. Please wait.

Presentation is loading. Please wait.

Tuning Queries from (E&N)

Similar presentations


Presentation on theme: "Tuning Queries from (E&N)"— Presentation transcript:

1 Tuning Queries from (E&N)
1/14/2019 Tuning Queries from (E&N) Copyright © 2004 Pearson Education, Inc.

2 Tuning Queries Indications for tuning queries
A query issues too many disk accesses The query plan shows that relevant indexes are not being used.

3 Typical instances for query tuning
Many query optimizers do not use indexes in the presence of arithmetic expressions (salary/365 > 10.5) numerical comparisons of attributes of different sizes and precision, (A=B and A is of type integer, B is of type smallinteger) NULL comparisons, and sub-string comparisons. (BDate is NULL)

4 Typical instances for query tuning
Indexes are often not used for nested queries using IN; SELECT ssn FROM employee WHERE dno IN (SELECT dnumber FROM department WHERE mgr_ssn = ‘555’);

5 Typical instances for query tuning
Some DISTINCTs may be redundant and can be avoided without changing the result. DISTINCT often causes a sort operation and must be operated if possible Unnecessary use of temporary result tables can be avoided by collapsing multiple queries into a single query unless the temporary relation is needed for some intermediate processing.

6 Typical instances for query tuning
In some situations involving using of correlated queries, temporaries are useful. SELECT ssn FROM employee e WHERE salary = SELECT MAX (salary) FROM employee AS m WHERE m.dno = e.dno;

7 Typical instances for query tuning
SELECT MAX(salary) AS high_salary, dno into TEMP FROM employee GROUP BY dno; SELECT ssn FROM employee e, temp t WHERE salary=high_salary and e.dno=t.dno;

8 Typical instances for query tuning
If multiple options for join condition are possible, choose one that uses a clustering index and avoid those that contain string comparisons.

9 Typical instances for query tuning
The order of tables in the FROM clause may affect the join processing Some query optimizers perform worse on nested queries compared to their equivalent un-nested counterparts. Many applications are based on views that define the data of interest to those applications. Sometimes these views become an overkill.

10 Additional Query Tuning Guidelines
A query with multiple selection conditions that are connected via OR may not be prompting the query optimizer to use any index. Such a query may be split up and expressed as a union of queries, each with a condition on an attribute that causes an index to be used.

11 Additional Query Tuning Guidelines
Apply the following transformations NOT condition may be transformed into a positive expression. Embedded SELECT blocks may be replaced by joins. If an equality join is set up between two tables, the range predicate on the joining attribute set up in one table may be repeated for the other table WHERE conditions may be rewritten to utilize the indexes on multiple columns.


Download ppt "Tuning Queries from (E&N)"

Similar presentations


Ads by Google