SQL Statement Optimization Series One

Source: Internet
Author: User

SQL statement OptimizationAvoid using ' * ' 2 in the 1.SELECT clause. Alias for use table when you concatenate multiple tables in an SQL statement, use the alias of the table and prefix the alias to each Column.  In this way, you can reduce the parsing time and reduce the syntax errors caused by the Column ambiguity. 3. Replace > Efficient with >=: SELECT * from emp where DEPTNO >=4 inefficient: SELECT * from emp where DEPTNO >3 The difference is that the former DBMS will be straight A record that jumps to the first DEPT equals 4 and the latter navigates to the Deptno=3 record and scans forward to the first record with a DEPT greater than 3. 4. Optimize GROUP BY: increase the efficiency of the group BY statement by filtering out unwanted records before group by. The following two queries return the same results but the second one is significantly faster. Inefficient: SELECT JOB, AVG (SAL) from EMPGROUP job has job = ' president ' OR job = ' MANAGER ' Efficient: SELECT JOB, AVG (SAL) from EMPWHERE job = ' president ' OR job = ' MANAGER ' GROUP job Note: To avoid having a HAVING clause, the having will only filter the result set after retrieving all records. This processing requires sorting, totals, and so on. If you can limit the number of records through the WHERE clause, you can reduce this overhead.

SQL Statement Optimization Series One

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.