baseline学习1

1.有关的两个参数

NAME                                 TYPE        VALUE
------------------------------------ ----------- ------------------------------
optimizer_capture_sql_plan_baselines boolean     TRUE
optimizer_use_sql_plan_baselines     boolean     TRUE


SQL> create table t1 nologging as select object_id,created from dba_objects;

Table created.

SQL> alter session set nls_data_format='yyyy/mm/dd hh24:mi:ss';
alter session set nls_data_format='yyyy/mm/dd hh24:mi:ss'
*
ERROR at line 1:
ORA-00922: missing or invalid option


SQL> alter session set nls_date_format='yyyy/mm/dd hh24:mi:ss';

Session altered.

SQL> exec :object_id :=72443

PL/SQL procedure successfully completed.

SQL> exec :created :='2010/09/05 06:16:41'

PL/SQL procedure successfully completed.

SQL>
SQL> set autot traceonly exp stat
SQL> select  * from t1 where object_id=:object_id and created=:created;

no rows selected


Execution Plan
----------------------------------------------------------
Plan hash value: 3617692013

--------------------------------------------------------------------------
| Id  | Operation         | Name | Rows  | Bytes | Cost (%CPU)| Time     |
--------------------------------------------------------------------------
|   0 | SELECT STATEMENT  |      |     8 |   176 |    46   (3)| 00:00:01 |
|*  1 |  TABLE ACCESS FULL| T1   |     8 |   176 |    46   (3)| 00:00:01 |
--------------------------------------------------------------------------

Predicate Information (identified by operation id):
---------------------------------------------------

   1 - filter("OBJECT_ID"=TO_NUMBER(:OBJECT_ID) AND "CREATED"=:CREATED)

Note
-----
   - dynamic sampling used for this statement (level=2)
   - SQL plan baseline "SQL_PLAN_975htc2jdg7m8dbd90e8e" used for this statement


Statistics
----------------------------------------------------------
         40  recursive calls
         52  db block gets
        289  consistent gets
        181  physical reads
       5848  redo size
        406  bytes sent via SQL*Net to client
        513  bytes received via SQL*Net from client
          1  SQL*Net roundtrips to/from client
          0  sorts (memory)
          0  sorts (disk)
          0  rows processed

SQL> /

no rows selected


Execution Plan
----------------------------------------------------------
Plan hash value: 3617692013

--------------------------------------------------------------------------
| Id  | Operation         | Name | Rows  | Bytes | Cost (%CPU)| Time     |
--------------------------------------------------------------------------
|   0 | SELECT STATEMENT  |      |     8 |   176 |    46   (3)| 00:00:01 |
|*  1 |  TABLE ACCESS FULL| T1   |     8 |   176 |    46   (3)| 00:00:01 |
--------------------------------------------------------------------------

Predicate Information (identified by operation id):
---------------------------------------------------

   1 - filter("OBJECT_ID"=TO_NUMBER(:OBJECT_ID) AND "CREATED"=:CREATED)

Note
-----
   - dynamic sampling used for this statement (level=2)
   - SQL plan baseline "SQL_PLAN_975htc2jdg7m8dbd90e8e" used for this statement


Statistics
----------------------------------------------------------
          5  recursive calls
          0  db block gets
        257  consistent gets
         41  physical reads
          0  redo size
        406  bytes sent via SQL*Net to client
        513  bytes received via SQL*Net from client
          1  SQL*Net roundtrips to/from client
          0  sorts (memory)
          0  sorts (disk)
          0  rows processed

SQL> exec dbms_stats.gather_table_stats(user,'t1');

PL/SQL procedure successfully completed.

SQL> l
  1* select  * from t1 where object_id=:object_id and created=:created
SQL> /

no rows selected


Execution Plan
----------------------------------------------------------
Plan hash value: 3617692013

--------------------------------------------------------------------------
| Id  | Operation         | Name | Rows  | Bytes | Cost (%CPU)| Time     |
--------------------------------------------------------------------------
|   0 | SELECT STATEMENT  |      |     1 |    13 |    46   (3)| 00:00:01 |
|*  1 |  TABLE ACCESS FULL| T1   |     1 |    13 |    46   (3)| 00:00:01 |
--------------------------------------------------------------------------

Predicate Information (identified by operation id):
---------------------------------------------------

   1 - filter("OBJECT_ID"=TO_NUMBER(:OBJECT_ID) AND "CREATED"=:CREATED)

Note
-----
   - SQL plan baseline "SQL_PLAN_975htc2jdg7m8dbd90e8e" used for this statement


Statistics
----------------------------------------------------------
          0  recursive calls
          0  db block gets
        184  consistent gets
          0  physical reads
          0  redo size
        406  bytes sent via SQL*Net to client
        513  bytes received via SQL*Net from client
          1  SQL*Net roundtrips to/from client
          0  sorts (memory)
          0  sorts (disk)
          0  rows processed

SQL> create index idx_object_id on t1(object_id);

Index created.

SQL> create index idx_created on t1(created);

Index created.

SQL> l
  1* create index idx_created on t1(created)
SQL> select  * from t1 where object_id=:object_id and created=:created;

no rows selected


Execution Plan
----------------------------------------------------------
Plan hash value: 3617692013

--------------------------------------------------------------------------
| Id  | Operation         | Name | Rows  | Bytes | Cost (%CPU)| Time     |
--------------------------------------------------------------------------
|   0 | SELECT STATEMENT  |      |     1 |    13 |    46   (3)| 00:00:01 |
|*  1 |  TABLE ACCESS FULL| T1   |     1 |    13 |    46   (3)| 00:00:01 |
--------------------------------------------------------------------------

Predicate Information (identified by operation id):
---------------------------------------------------

   1 - filter("OBJECT_ID"=TO_NUMBER(:OBJECT_ID) AND "CREATED"=:CREATED)

Note
-----
   - SQL plan baseline "SQL_PLAN_975htc2jdg7m8dbd90e8e" used for this statement


Statistics
----------------------------------------------------------
         26  recursive calls
         35  db block gets
        219  consistent gets
          2  physical reads
       4056  redo size
        406  bytes sent via SQL*Net to client
        513  bytes received via SQL*Net from client
          1  SQL*Net roundtrips to/from client
          0  sorts (memory)
          0  sorts (disk)
          0  rows processed

SQL> /

no rows selected


Execution Plan
----------------------------------------------------------
Plan hash value: 3617692013

--------------------------------------------------------------------------
| Id  | Operation         | Name | Rows  | Bytes | Cost (%CPU)| Time     |
--------------------------------------------------------------------------
|   0 | SELECT STATEMENT  |      |     1 |    13 |    46   (3)| 00:00:01 |
|*  1 |  TABLE ACCESS FULL| T1   |     1 |    13 |    46   (3)| 00:00:01 |
--------------------------------------------------------------------------

Predicate Information (identified by operation id):
---------------------------------------------------

   1 - filter("OBJECT_ID"=TO_NUMBER(:OBJECT_ID) AND "CREATED"=:CREATED)

Note
-----
   - SQL plan baseline "SQL_PLAN_975htc2jdg7m8dbd90e8e" used for this statement


Statistics
----------------------------------------------------------
          6  recursive calls
          5  db block gets
        185  consistent gets
          0  physical reads
         96  redo size
        406  bytes sent via SQL*Net to client
        513  bytes received via SQL*Net from client
          1  SQL*Net roundtrips to/from client
          0  sorts (memory)
          0  sorts (disk)
          0  rows processed

SQL> exec dbms_stats.gather_table_stats(user,'t1',cascade=>true);

PL/SQL procedure successfully completed.

SQL> l
  1* select  * from t1 where object_id=:object_id and created=:created
SQL> /

no rows selected


Execution Plan
----------------------------------------------------------
Plan hash value: 3617692013

--------------------------------------------------------------------------
| Id  | Operation         | Name | Rows  | Bytes | Cost (%CPU)| Time     |
--------------------------------------------------------------------------
|   0 | SELECT STATEMENT  |      |     1 |    13 |    46   (3)| 00:00:01 |
|*  1 |  TABLE ACCESS FULL| T1   |     1 |    13 |    46   (3)| 00:00:01 |
--------------------------------------------------------------------------

Predicate Information (identified by operation id):
---------------------------------------------------

   1 - filter("OBJECT_ID"=TO_NUMBER(:OBJECT_ID) AND "CREATED"=:CREATED)

Note
-----
   - SQL plan baseline "SQL_PLAN_975htc2jdg7m8dbd90e8e" used for this statement


Statistics
----------------------------------------------------------
          0  recursive calls
          0  db block gets
        183  consistent gets
          0  physical reads
          0  redo size
        406  bytes sent via SQL*Net to client
        513  bytes received via SQL*Net from client
          1  SQL*Net roundtrips to/from client
          0  sorts (memory)
          0  sorts (disk)
          0  rows processed



--将全表扫描的PLAN_NAME=‘SQL_PLAN_975htc2jdg7m8dbd90e8e’ DISABLE

SQL> DECLARE
  2   l_plans_altered  PLS_INTEGER;
  3  BEGIN
  4   l_plans_altered := DBMS_SPM.alter_sql_plan_baseline(
  5     sql_handle      => 'SQL_93961960a2d79e68',
  6      plan_name       => 'SQL_PLAN_975htc2jdg7m8dbd90e8e',
  7     attribute_name  => 'ENABLED',
  8     attribute_value => 'NO');
  9   DBMS_OUTPUT.put_line('Plans Altered: ' || l_plans_altered);
 10  END;
 11  /
Plans Altered: 1

PL/SQL procedure successfully completed.


可以看到已经走回正常的执行计划

  1* select  * from t1 where object_id=:object_id and created=:created
SQL> /

Execution Plan
----------------------------------------------------------
Plan hash value: 2724989281

---------------------------------------------------------------------------------------------
| Id  | Operation                   | Name          | Rows  | Bytes | Cost (%CPU)| Time     |
---------------------------------------------------------------------------------------------
|   0 | SELECT STATEMENT            |               |     1 |    13 |     2   (0)| 00:00:01 |
|*  1 |  TABLE ACCESS BY INDEX ROWID| T1            |     1 |    13 |     2   (0)| 00:00:01 |
|*  2 |   INDEX RANGE SCAN          | IDX_OBJECT_ID |     1 |       |     1   (0)| 00:00:01 |
---------------------------------------------------------------------------------------------

Predicate Information (identified by operation id):
---------------------------------------------------

   1 - filter("CREATED"=:CREATED)
   2 - access("OBJECT_ID"=TO_NUMBER(:OBJECT_ID))




删除baseline

SQL> declare
  2  n PLS_INTEGER;
  3  begin
  4  n :=DBMS_SPM.DROP_SQL_PLAN_BASELINE (
  5  sql_handle=>'SQL_93961960a2d79e68',
  6  plan_name=> NULL)
  7  ;
  8  dbms_output.put_line(n);
  9  end;
 10  /

PL/SQL procedure successfully completed.

相对应的文档语法

DROP_SQL_PLAN_BASELINE Function
This function drops a single plan, or all plans associated with a SQL statement.
Syntax
DBMS_SPM.DROP_SQL_PLAN_BASELINE (
sql_handle IN VARCHAR2 := NULL,
plan_name IN VARCHAR2


这里有个问题,删除完baseline后,在同一个会话中,再次执行同样的主句,并不会被系统重新自动捕获;

  1* select  * from t1 where object_id=:object_id and created=:created
SQL> /

Execution Plan
----------------------------------------------------------
Plan hash value: 2724989281

---------------------------------------------------------------------------------------------
| Id  | Operation                   | Name          | Rows  | Bytes | Cost (%CPU)| Time     |
---------------------------------------------------------------------------------------------
|   0 | SELECT STATEMENT            |               |     1 |    13 |     2   (0)| 00:00:01 |
|*  1 |  TABLE ACCESS BY INDEX ROWID| T1            |     1 |    13 |     2   (0)| 00:00:01 |
|*  2 |   INDEX RANGE SCAN          | IDX_OBJECT_ID |     1 |       |     1   (0)| 00:00:01 |
---------------------------------------------------------------------------------------------

Predicate Information (identified by operation id):
---------------------------------------------------

   1 - filter("CREATED"=:CREATED)
   2 - access("OBJECT_ID"=TO_NUMBER(:OBJECT_ID))


而需要重新新开一个会话执行

 1* select  * from t1 where object_id=:object_id and created=:created
SQL> /

no rows selected


Execution Plan
----------------------------------------------------------
Plan hash value: 2724989281

---------------------------------------------------------------------------------------------
| Id  | Operation                   | Name          | Rows  | Bytes | Cost (%CPU)| Time     |
---------------------------------------------------------------------------------------------
|   0 | SELECT STATEMENT            |               |     1 |    13 |     2   (0)| 00:00:01 |
|*  1 |  TABLE ACCESS BY INDEX ROWID| T1            |     1 |    13 |     2   (0)| 00:00:01 |
|*  2 |   INDEX RANGE SCAN          | IDX_OBJECT_ID |     1 |       |     1   (0)| 00:00:01 |
---------------------------------------------------------------------------------------------

Predicate Information (identified by operation id):
---------------------------------------------------

   1 - filter("CREATED"=:CREATED)
   2 - access("OBJECT_ID"=TO_NUMBER(:OBJECT_ID))

Note
-----
   - SQL plan baseline "SQL_PLAN_975htc2jdg7m890704d19" used for this statement


Statistics
----------------------------------------------------------
          0  recursive calls
          0  db block gets
          3  consistent gets
          0  physical reads
          0  redo size
        406  bytes sent via SQL*Net to client
        513  bytes received via SQL*Net from client
          1  SQL*Net roundtrips to/from client
          0  sorts (memory)
          0  sorts (disk)
          0  rows processed



### 深度学习中的 Baseline 模型 在深度学习的研究和应用过程中,Baseline 是指一种用于衡量其他更复杂模型性能的基础模型或方法。它通常是一个简单的、易于实现的模型,能够提供一个初步的结果作为后续优化的目标参考点[^2]。 #### 定义与作用 Baseline 的主要目的是为新模型的设计和改进提供一个清晰的标准。通过对比不同模型的表现,研究人员可以判断新的架构或算法是否有显著提升。例如,在图像分类任务中,可以选择逻辑回归或者卷积神经网络(CNN)作为一个基础模型,并将其结果视为基准线。随后在此基础上尝试引入更深的网络结构或其他技术手段来进一步改善效果[^3]。 #### 构建方式 构建 Baseline 可以采用多种策略: - **预训练模型**:如果存在针对特定领域已有的高质量预训练权重,则可以直接加载这些参数并微调至当前任务上; - **简单模型**:对于某些场景来说,即使是最基本的传统机器学习算法也可能成为有效的起点,比如支持向量机(SVM) 或随机森林(Random Forests); 当涉及到具体应用场景时,还需要考虑数据特性以及计算资源等因素综合决定最适合自己的方案。 ```python from sklearn.linear_model import LogisticRegression from keras.models import Sequential from keras.layers import Dense, Conv2D, Flatten # Example of a simple logistic regression as baseline model def create_logistic_baseline(): lr = LogisticRegression() return lr # Example of CNN-based deep learning baseline using Keras framework def build_cnn_baseline(input_shape): model = Sequential() model.add(Conv2D(32,(3,3),activation='relu',input_shape=input_shape)) model.add(Flatten()) model.add(Dense(units=10, activation="softmax")) return model ``` 上述代码展示了如何创建两个不同的基线模型——一个是传统的逻辑回归,另一个则是基于卷积层的小型神经网络。这两种都可以视作各自类别下的初始参照物。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值