单表hint

index

index_hint ::=

确定在表t1上利用给出的索引进行扫描。如果只给出一个索引名,表示指定使用该索引进行表扫描;如果给出多个索引名,则表示在多个索引中选择一个进行表扫描;如果不给出索引名,则优化器考虑t1上的所有可用索引,并从中选择代价最小者。

举例:

--  清理环境
DROP TABLE t1 CASCADE;

--  创建表
CREATE TABLE t1(tc1 INT, tc2 INT);
CREATE INDEX idx_t1_tc1 ON t1(tc1);
CREATE INDEX idx_t1_tc2 ON t1(tc2);


explain select /*+ index(t1 idx_t1_tc1, idx_t1_tc2)*/ * from t1
    where tc1 > 1 and tc2 > 2;
QUERY PLAN(text)      
----------------------
Index Scan using IDX_T1_TC2(Normal Index Scan) on T1  (cost=0.00..43.14 rows=910 width=8)
  Index Key: (TC2 > 2)
  Table Filter: (TC1 > 1)
总数目:3

--  删除表
DROP TABLE t1;

no_index

no_index_hint ::=

确定不利用表t1上的索引对表t1进行表扫描。如果只给出一个索引名,表示不使用该索引进行扫描;如果给出多个索引,则表示所列出的多个索引都不考虑;如果不给出索引,则表示表t1上的所有索引扫描都不考虑。

举例:

--  清理环境
DROP TABLE t1 CASCADE;

--  创建表
CREATE TABLE t1(tc1 INT, tc2 INT);
CREATE INDEX idx_t1_tc1 ON t1(tc1);
CREATE INDEX idx_t1_tc2 ON t1(tc2);


explain select /*+ no_index(t1 idx_t1_tc1, idx_t1_tc2)*/ * from t1
    where tc1 > 1 and tc2 > 2;
QUERY PLAN(text)      
----------------------
Seq Scan on T1  (cost=0.00..130.88 rows=910 width=8)
  Scan Key: ((TC1 > 1) AND (TC2 > 2))
总数目:2

--  删除表
DROP TABLE t1;

full

full ::=

确定在表t1上使用seqscan计划。

举例:

--  清理环境
DROP TABLE t1 CASCADE;

--  创建表
CREATE TABLE t1(tc1 INT, tc2 INT);


explain select /*+ full(t1)*/ * from t1 where tc1 > 1;
QUERY PLAN(text)      
----------------------
Seq Scan on T1  (cost=0.00..110.40 rows=2731 width=8)
  Scan Key: (TC1 > 1)
总数目:2

--  删除表
DROP TABLE t1;

bm_index

bm_index_hint ::=

确定在表t1上使用bitmapindexjoin,该bitmapindexjoin由索引index_1和index_2组合而成。

举例:

--  清理环境
DROP TABLE t1 CASCADE;

--  创建表
CREATE TABLE t1(tc1 INT, tc2 INT);
CREATE INDEX idx_t1_tc1 ON t1(tc1);
CREATE INDEX idx_t1_tc2 ON t1(tc2);


explain select /*+ bm_index(t1 idx_t1_tc1 idx_t1_tc2)*/ * from t1
    where tc1 > 1 or tc2 > 2;
QUERY PLAN(text)      
----------------------
Seq Scan on T1  (cost=100000000.00..100000130.88 rows=4551 width=8)
  Scan Filter: ((TC1 > 1) OR (TC2 > 2))
总数目:2

--  删除表
DROP TABLE t1;

no_bm_index

no_bm_index_hint ::=

确定在表t1上不使用bitmapindexjoin,该bitmapindexjoin由索引index_1和index_2组合而成。如果不给出索引参数,则优化器不考虑该表上所有的bitmapindexjoin计划。

举例:

--  清理环境
DROP TABLE t1 CASCADE;

--  创建表
CREATE TABLE t1(tc1 INT, tc2 INT);
CREATE INDEX idx_t1_tc1 ON t1(tc1);
CREATE INDEX idx_t1_tc2 ON t1(tc2);


explain select /*+ no_bm_index(t1 idx_t1_tc1 idx_t1_tc2)*/ * from t1
    where tc1 > 1 or tc2 > 2;
QUERY PLAN(text)      
----------------------
Index Scan using IDX_T1_TC1(Normal Index Scan), IDX_T1_TC2(Normal Index Scan) on T1  (cost=0.00..86.28 rows=4551 width=8)
  Index Key: ((TC1 > 1) OR (TC2 > 2))
  Index Filter: (TRUE OR TRUE)
总数目:3

--  删除表
DROP TABLE t1;