12
返回列表 发新帖
楼主: autumn_leaf

请教如何保证一张表或者是IOT能永远CACHE 在内存里?不会被踢出去?

[复制链接]
论坛徽章:
5
ITPUB新首页上线纪念徽章
日期:2007-10-20 08:38:44数据库板块每日发贴之星
日期:2007-12-10 01:03:50ITPUB8周年纪念徽章
日期:2009-09-27 10:21:21鲜花蛋
日期:2012-03-24 10:51:55灰彻蛋
日期:2012-03-24 19:58:31
11#
 楼主| 发表于 2012-3-29 23:18 | 只看该作者
本帖最后由 autumn_leaf 于 2012-3-29 23:19 编辑

我在应用程序里没法全表扫描啊,只能 COUNT(*),可是COUNT( * ) 更本没把数据加载到KEEP 池
  drop table test;
  create table test
  (
    myid         number(6),
    mysum        number(16,4),
    constraint   pk_test primary key(myid)
  ) organization index nologging;
  
  insert into  test select rownum,rownum from dba_objects where rownum<=10000;
  commit;
  
  alter table test storage (buffer_pool keep);

alter system flush buffer_cache;
set autot trace
select count(*) from test;

        131  recursive calls
          0  db block gets
         69  consistent gets
         32  physical reads
         80  redo size
        411  bytes sent via SQL*Net to client
        385  bytes received via SQL*Net from client
          2  SQL*Net roundtrips to/from client
          3  sorts (memory)
          0  sorts (disk)
          1  rows processed

select * from test;
         67  recursive calls
          0  db block gets
        726  consistent gets
          7  physical reads
          0  redo size
     176731  bytes sent via SQL*Net to client
       7711  bytes received via SQL*Net from client
        668  SQL*Net roundtrips to/from client
          2  sorts (memory)
          0  sorts (disk)
      10000  rows processed

使用道具 举报

回复
论坛徽章:
5
ITPUB新首页上线纪念徽章
日期:2007-10-20 08:38:44数据库板块每日发贴之星
日期:2007-12-10 01:03:50ITPUB8周年纪念徽章
日期:2009-09-27 10:21:21鲜花蛋
日期:2012-03-24 10:51:55灰彻蛋
日期:2012-03-24 19:58:31
12#
 楼主| 发表于 2012-3-29 23:30 | 只看该作者
我想首先确定一个问题
是否只要我的KEEP池足够大,就可以保证我的表一定会cache在KEEP池里?
比如KEEP池 30M,我的表永远只有 20M ?然后我全表扫描一次表,
即使我不再使用这个表,只要数据库不启动,不清缓存,我的表永远会在KEEP池里?

使用道具 举报

回复
论坛徽章:
47
蒙奇·D·路飞
日期:2017-03-27 08:04:23马上有车
日期:2014-02-18 16:41:112014年新春福章
日期:2014-02-18 16:41:11一汽
日期:2013-09-01 20:46:27复活蛋
日期:2013-03-13 07:55:232013年新春福章
日期:2013-02-25 14:51:24ITPUB 11周年纪念徽章
日期:2012-10-09 18:03:322012新春纪念徽章
日期:2012-02-13 15:13:202012新春纪念徽章
日期:2012-02-13 15:13:202012新春纪念徽章
日期:2012-02-13 15:13:20
13#
发表于 2012-3-30 03:28 | 只看该作者
本帖最后由 Yong Huang 于 2012-3-29 13:46 编辑

> 我不清楚怎么把索引放到KEEP池了

If it's not a primary key index, try
alter index indexname storage (buffer_pool keep);

If it's IOT, I think it's just
alter table test storage (buffer_pool keep);

Answer to your message #11:

If you check the buffer status before you drop the table, they're all exclusive current. (I ran the test as user system in Oracle 10.2.0.4.)

SQL> select file_id, block_id, blocks from dba_extents where segment_name = 'PK_TEST' and owner = 'SYSTEM';

   FILE_ID   BLOCK_ID     BLOCKS
---------- ---------- ----------
         1      60809          8
         1      60857          8
         1      60897          8

SQL> select distinct status from v$bh where file# = 1 and (block# between 60809 and 60816 or block# between 60857 and 60864 or block# between 60897 and 60904);

STATUS
-------
xcur

After you drop the table, they all become free. Immediately after you recreate the table (and suppose the database has no other activity), the *exactly same* blocks of the segment become xcur again. So they can readily be reused.

The above is true even if you don't assign the table to the keep pool. To properly test the effect of the keep pool, you have to configure a small buffer cache default pool, and a keep pool at least as large as the segment size, and run SQLs that cause all kinds of other table blocks to be cached in the default pool.

Answer to #12:

Please stop asking questions and start to do more test.

使用道具 举报

回复
论坛徽章:
86
2015中国数据库技术大会纪念徽章
日期:2015-04-24 16:04:24马上有车
日期:2014-02-19 11:55:14马上有车
日期:2014-02-18 16:41:112014年新春福章
日期:2014-02-18 16:41:11优秀写手
日期:2013-12-18 09:29:11日产
日期:2013-10-17 08:44:39马自达
日期:2013-08-26 16:28:022013年新春福章
日期:2013-02-25 14:51:24ITPUB 11周年纪念徽章
日期:2012-10-23 16:55:51马上有房
日期:2014-02-19 11:55:14
14#
发表于 2012-3-30 09:29 | 只看该作者
有趣的现象,alter table test storage (buffer_pool keep);是否不是即时生效?

使用道具 举报

回复
论坛徽章:
47
蒙奇·D·路飞
日期:2017-03-27 08:04:23马上有车
日期:2014-02-18 16:41:112014年新春福章
日期:2014-02-18 16:41:11一汽
日期:2013-09-01 20:46:27复活蛋
日期:2013-03-13 07:55:232013年新春福章
日期:2013-02-25 14:51:24ITPUB 11周年纪念徽章
日期:2012-10-09 18:03:322012新春纪念徽章
日期:2012-02-13 15:13:202012新春纪念徽章
日期:2012-02-13 15:13:202012新春纪念徽章
日期:2012-02-13 15:13:20
15#
发表于 2012-3-31 05:34 | 只看该作者
What do you mean by "即时生效"? The table property is immediately changed in the data dictionary. But the table blocks will have to be (re-)scanned to go to the keep pool.

使用道具 举报

回复
论坛徽章:
86
2015中国数据库技术大会纪念徽章
日期:2015-04-24 16:04:24马上有车
日期:2014-02-19 11:55:14马上有车
日期:2014-02-18 16:41:112014年新春福章
日期:2014-02-18 16:41:11优秀写手
日期:2013-12-18 09:29:11日产
日期:2013-10-17 08:44:39马自达
日期:2013-08-26 16:28:022013年新春福章
日期:2013-02-25 14:51:24ITPUB 11周年纪念徽章
日期:2012-10-23 16:55:51马上有房
日期:2014-02-19 11:55:14
16#
发表于 2012-4-1 11:01 | 只看该作者
按照楼主的测试,
insert into as select时使用的是default pool,然后变更到keep pool,进行查询时没有物理读,是否还是从default pool里直接读取呢?

使用道具 举报

回复
论坛徽章:
47
蒙奇·D·路飞
日期:2017-03-27 08:04:23马上有车
日期:2014-02-18 16:41:112014年新春福章
日期:2014-02-18 16:41:11一汽
日期:2013-09-01 20:46:27复活蛋
日期:2013-03-13 07:55:232013年新春福章
日期:2013-02-25 14:51:24ITPUB 11周年纪念徽章
日期:2012-10-09 18:03:322012新春纪念徽章
日期:2012-02-13 15:13:202012新春纪念徽章
日期:2012-02-13 15:13:202012新春纪念徽章
日期:2012-02-13 15:13:20
17#
发表于 2012-4-2 23:41 | 只看该作者
本帖最后由 Yong Huang 于 2012-4-2 09:46 编辑

Now I see what you mean. I think if the blocks are still in buffer cache, regardless which pool, there's only memory read, and the table storage attribute (buffer_pool keep) won't have a chance to take effect. As soon as one block has to be read from datafile into buffer cache, this block will go to the keep pool. When I have time, I'll test it. Basically, we need to go from x$bh.set_ds (working set address I think) to x$kcbwds and to x$kcbwbpd to find which pool the buffer is in. The following query can be simplified to do exactly that:

select decode(pd.bp_id,1,'KEEP',2,'RECYCLE',3,'DEFAULT',4,'2K SUBCACHE',5,'4K SUBCACHE',
   6,'8K SUBCACHE',7,'16K SUBCACHE',8,'32K SUBCACHE','UNKNOWN') subcache,
   bh.object_name,bh.blocks
from x$kcbwds ds, x$kcbwbpd pd,
     (select /*+ use_hash(x) */ set_ds, o.name object_name, count(*) BLOCKS
      from obj$ o, x$bh x
      where o.dataobj#=x.obj and x.state!=0 and o.owner#!=0 and o.name='&tablename'
      group by set_ds, o.name) bh
where ds.set_id>=pd.bp_lo_sid and ds.set_id<=pd.bp_hi_sid and pd.bp_size!=0 and ds.addr=bh.set_ds;

使用道具 举报

回复
论坛徽章:
86
2015中国数据库技术大会纪念徽章
日期:2015-04-24 16:04:24马上有车
日期:2014-02-19 11:55:14马上有车
日期:2014-02-18 16:41:112014年新春福章
日期:2014-02-18 16:41:11优秀写手
日期:2013-12-18 09:29:11日产
日期:2013-10-17 08:44:39马自达
日期:2013-08-26 16:28:022013年新春福章
日期:2013-02-25 14:51:24ITPUB 11周年纪念徽章
日期:2012-10-23 16:55:51马上有房
日期:2014-02-19 11:55:14
18#
发表于 2012-4-9 09:05 | 只看该作者
Yong Huang 发表于 2012-4-2 23:41
Now I see what you mean. I think if the blocks are still in buffer cache, regardless which pool, the ...

这个确实是最合理的做法,只是这时候是否依然遵从LRU算法?如果遵从,并且表里的块比较热的话,可能还会一直存在于default pool里。

不过,一般情况下,在哪也无所谓。呵呵

使用道具 举报

回复
论坛徽章:
47
蒙奇·D·路飞
日期:2017-03-27 08:04:23马上有车
日期:2014-02-18 16:41:112014年新春福章
日期:2014-02-18 16:41:11一汽
日期:2013-09-01 20:46:27复活蛋
日期:2013-03-13 07:55:232013年新春福章
日期:2013-02-25 14:51:24ITPUB 11周年纪念徽章
日期:2012-10-09 18:03:322012新春纪念徽章
日期:2012-02-13 15:13:202012新春纪念徽章
日期:2012-02-13 15:13:202012新春纪念徽章
日期:2012-02-13 15:13:20
19#
发表于 2012-4-9 23:16 | 只看该作者
> 这时候是否依然遵从LRU算法?

I remember reading documents saying the LRU (actually modified LRU) algorithm still applies. Indeed, if the block is always hot, it will never have a chance to go to the pool you assigned. You can force that by flushing buffer_cache.

使用道具 举报

回复

您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

TOP技术积分榜 社区积分榜 徽章 团队 统计 知识索引树 积分竞拍 文本模式 帮助
  ITPUB首页 | ITPUB论坛 | 数据库技术 | 企业信息化 | 开发技术 | 微软技术 | 软件工程与项目管理 | IBM技术园地 | 行业纵向讨论 | IT招聘 | IT文档
  ChinaUnix | ChinaUnix博客 | ChinaUnix论坛
CopyRight 1999-2011 itpub.net All Right Reserved. 北京盛拓优讯信息技术有限公司版权所有 联系我们 未成年人举报专区 
京ICP备16024965号-8  北京市公安局海淀分局网监中心备案编号:11010802021510 广播电视节目制作经营许可证:编号(京)字第1149号
  
快速回复 返回顶部 返回列表