如何知道查询是在内存数据库还是磁盘数据库上运行

How to know the query is operating on in-memory database or disc database

我正在尝试针对基于磁盘的数据库测量内存数据库在 oracle 12c 中的查询执行时间。在客户端,我使用 JDBC 来触发查询。

我怎么知道查询是在内存中还是在磁盘中查找所需的数据库?是否有任何选项告诉 oracle 数据库服务器首先在 in-memory 中查找数据库,然后在 disc 中查找数据库?

How do I know that whether the query looks for required database in in-memory or in disc?

在Execution Plan中可以看到oracle是查了内存还是查了磁盘的数据,如下图。

SQL> desc t1
 Name                      Null?    Type
 ----------------------------------------- -------- ----------------------------
 COL1                           VARCHAR2(20)
 COL2                           VARCHAR2(20)

SQL> alter table t1 inmemory;

Table altered.

SQL> explain plan for select * from t1;

Explained.

SQL> select * from table(dbms_xplan.display());
Plan hash value: 3617692013

------------------------------------------------------------------------
| Id  | Operation          | Name | Rows  | Bytes | Cost (%CPU)|
------------------------------------------------------------------------
|   0 | SELECT STATEMENT       |      | 1 |    24 | 0   (0)|
|   1 |  TABLE ACCESS INMEMORY FULL| T1   | 1 |    24 |        |
------------------------------------------------------------------------

8 rows selected.

SQL> alter table t1 no inmemory;

Table altered.

SQL> explain plan for select * from t1;

Explained.

SQL> select * from table(dbms_xplan.display());
Plan hash value: 3617692013

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

8 rows selected.

Is there any option that tells the oracle db server that look for the database first into in-memory and then into disc?

Oracle 文档说-

INMEMORY_QUERY is used to enable or disable in-memory queries for the entire database at the session or system level. This parameter is helpful when you want to test workloads with and without the use of the In-Memory Column Store (IM column store).

您将内存查询禁用为:

SQL> alter session set inmemory_query = disable;

您给优化器 INMEMORY 提示以查看内存中的数据,如下所示。

select /*+ INMEMORY */ * from t1;