Home > Database > Mysql Tutorial > 三十种SQL语句优化方法(1/4)

三十种SQL语句优化方法(1/4)

WBOY
Release: 2016-06-07 17:47:43
Original
1179 people have browsed it
1. /*+all_rows*/


表明对语句块选择基于开销的优化方法,并获得最佳吞吐量,使资源消耗最小化.
例如:

select /*+all+_rows*/ emp_no,emp_nam,dat_in from bsempms where emp_no='scott';


2. /*+first_rows*/
表明对语句块选择基于开销的优化方法,并获得最佳响应时间,使资源消耗最小化.
例如:

select /*+first_rows*/ emp_no,emp_nam,dat_in from bsempms where emp_no='scott';

3. /*+choose*/
表明如果数据字典中有访问表的统计信息,将基于开销的优化方法,并获得最佳的吞吐量;
表明如果数据字典中没有访问表的统计信息,将基于规则开销的优化方法;
例如:

select /*+choose*/ emp_no,emp_nam,dat_in from bsempms where emp_no='scott';

4. /*+rule*/
表明对语句块选择基于规则的优化方法.
例如:

select /*+ rule */ emp_no,emp_nam,dat_in from bsempms where emp_no='scott';

5. /*+full(table)*/
表明对表选择全局扫描的方法.
例如:

select /*+full(a)*/ emp_no,emp_nam from bsempms a where emp_no='scott';

6. /*+rowid(table)*/
提示明确表明对指定表根据rowid进行访问.
例如:

select /*+rowid(bsempms)*/ * from bsempms where rowid>='aaaaaaaaaaaaaa'
and emp_no='scott';

7. /*+cluster(table)*/
提示明确表明对指定表选择簇扫描的访问方法,它只对簇对象有效.
例如:

select /*+cluster */ bsempms.emp_no,dpt_no from bsempms,bsdptms
where dpt_no='tec304' and bsempms.dpt_no=bsdptms.dpt_no;

8. /*+index(table index_name)*/
表明对表选择索引的扫描方法.
例如:

select /*+index(bsempms sex_index) use sex_index because there are fewmale bsempms */ from bsempms where sex='m';

9. /*+index_asc(table index_name)*/
表明对表选择索引升序的扫描方法.
例如:

select /*+index_asc(bsempms pk_bsempms) */ from bsempms where dpt_no='scott';

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template