一:创建测试数据
create table t1 as select * from dba_objects; update t1 set object_id=1 where rownum=1; obclient> select object_id,count(*) from tbcs.t1 group by object_id; +------+----------+ | ID | COUNT(*) | +------+----------+ | 1 | 786432 | | 2 | 1 | +------+----------+ 2 rows in set (0.67 sec)
二:执行计划突变测试验证
实验1 --第一次传参为大账号
obclient> set @v1=1; Query OK, 0 rows affected (0.00 sec) obclient> select count(owner) from t1 where object_id=@v1; +--------------+ | COUNT(OWNER) | +--------------+ | 695295 | +--------------+ 1 row in set (0.57 sec) obclient> show trace; +-------+----------------------+------+ | TITLE | KEYVALUE | TIME | +-------+----------------------+------+ | NULL | PHY_SCALAR_AGGREGATE | NULL | | T1 | PHY_TABLE_SCAN | NULL | +-------+----------------------+------+ 2 rows in set (0.01 sec) obclient> set @v1=2; Query OK, 0 rows affected (0.00 sec) obclient> select count(owner) from t1 where object_id=@v1; +--------------+ | COUNT(OWNER) | +--------------+ | 1 | +--------------+ 1 row in set (0.00 sec) obclient> show trace; +-------+----------------------+------+ | TITLE | KEYVALUE | TIME | +-------+----------------------+------+ | NULL | PHY_SCALAR_AGGREGATE | NULL | | T1 | PHY_TABLE_SCAN | NULL | +-------+----------------------+------+ 2 rows in set (0.00 sec)
实验二:第二次传参为小账号
obclient> set @v1=2; Query OK, 0 rows affected (0.00 sec) obclient> select count(owner) from t1 where id=@v1; ORA-00904: invalid identifier 'ID' in 'where clause' obclient> select count(owner) from t1 where object_id=@v1; +--------------+ | COUNT(OWNER) | +--------------+ | 1 | +--------------+ 1 row in set (0.00 sec) obclient> show trace; +---------------+----------------------+------+ | TITLE | KEYVALUE | TIME | +---------------+----------------------+------+ | NULL | PHY_SCALAR_AGGREGATE | NULL | | T1(IDX_T1_ID) | PHY_TABLE_SCAN | NULL | +---------------+----------------------+------+ 2 rows in set (0.01 sec) obclient> set @v1=1; Query OK, 0 rows affected (0.00 sec) obclient> select count(owner) from t1 where object_id=@v1; +--------------+ | COUNT(OWNER) | +--------------+ | 695295 | +--------------+ 1 row in set (2.29 sec) obclient> show trace; +---------------+----------------------+------+ | TITLE | KEYVALUE | TIME | +---------------+----------------------+------+ | NULL | PHY_SCALAR_AGGREGATE | NULL | | T1(IDX_T1_ID) | PHY_TABLE_SCAN | NULL | +---------------+----------------------+------+