简体   繁体   English

Oracle OCI不查询缓存结果

[英]Oracle OCI not to query cached result

I am developing a C++ program using OCI to query some result set from a Oracle database. 我正在使用OCI开发C ++程序,以从Oracle数据库查询某些结果集。 I found that the result set is cached even I've manually update rows with ' update table set col=xxx where xxx '. 我发现即使我已经用' update table set col=xxx where xxx '手动更新了行,结果集仍被缓存。 The OCI calls are still getting old data. OCI呼叫仍在获取旧数据。 How does this caching happen? 这种缓存如何发生? Is there a way to disable it? 有没有办法禁用它? How can I check if the caching really happens? 如何检查缓存是否真的发生? By checking execution plan? 通过检查执行计划?

When you make changes in a separate session (your SQL*Plus session), those changes only become visible to your current session (your OCI application) when you commit the changes. 当您在单独的会话(SQL * Plus会话)中进行更改时,只有在commit更改后,这些更改才对当前会话(您的OCI应用程序)可见。 Until you commit the transaction in SQL*Plus, you will continue to see the current version of the row, not the version that you changed in your SQL*Plus session. 在用SQL * Plus commit事务之前,您将继续看到该行的当前版本,而不是您在SQL * Plus会话中更改的版本。 Your OCI application is using the default transaction isolation of READ COMMITTED so you can only read committed data. 您的OCI应用程序正在使用默认的事务隔离READ COMMITTED因此您只能读取已提交的数据。

One thing to be aware of is that if you open a cursor from your OCI application, the data that is fetched from the cursor handle is the data as it existed at the point in time that the cursor was opened. 要注意的一件事是,如果从OCI应用程序打开游标,则从游标句柄中获取的数据就是在打开游标时存在的数据。 So if you open a cursor in OCI, commit changes in SQL*Plus, and then fetch the data from OCI, your OCI application will not see the changes that were committed in SQL*Plus. 因此,如果您在OCI中打开游标,在SQL * Plus中提交更改,然后从OCI中获取数据,则您的OCI应用程序将看不到在SQL * Plus中提交的更改。 You would have to re-open the cursor in order to see the newly committed rows. 您必须重新打开游标才能查看新提交的行。

Technically, this is not caching. 从技术上讲,这不是缓存。 Instead, this is how Oracle's multi-version read consistency works. 相反,这就是Oracle多版本读取一致性的工作方式。 Assuming the default transaction isolation level, each time a cursor is opened, the current SCN (system change number) is captured and the data that is retrieved is as of that SCN. 假定使用默认事务隔离级别,则每次打开游标时,都会捕获当前的SCN(系统更改号),并且检索到的数据与该SCN相同。 If a block has changed (whether committed or not) since that SCN, Oracle applies the UNDO vector for that change to the block before returning it to your session. 如果自该SCN以来某个块发生了更改(无论是否已提交),则Oracle在将该更改返回到您的会话之前,对该块应用UNDO向量。

Yes you will need to commit in SQL*Plus, or SET AUTOCOMMIT ON . 是的,您将需要提交SQL * Plus或SET AUTOCOMMIT ON

Looking at the query plan will clearly show you if the client result cache is in use, you will see RESULT CACHE in the Operation column. 查看查询计划将清楚地显示您是否正在使用客户端结果缓存,您将在“ Operation列中看到“ RESULT CACHE缓存Operation

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM