ITPUB论坛-专业的IT技术社区

标题: select 大结果集如何存放 [打印本页]

作者: napolone1983    时间: 2011-10-28 18:01
标题: select 大结果集如何存放
oracle执行select操作,返回的结果集存放在什么位置?结果集中保存的是rowid集合还是真实的数据?返回的结果集是放在PGA区域么?如果返回的是真实的数据,那么如果数据量过大会不会造成内存溢出?请各位高手解答

作者: Yong Huang    时间: 2011-10-28 22:52
If it's a simple select * from table, the data goes straight to the client. If the SQL has some intermediate steps for data processing, such as select count(*) from table, UGA will be used. In dedicated config, UGA is part of PGA.

Yong Huang
作者: zhangfei__    时间: 2011-10-29 23:33
perfect !
作者: napolone1983    时间: 2011-10-29 23:59
本帖最后由 napolone1983 于 2011-10-30 00:05 编辑
Yong Huang 发表于 2011-10-28 22:52
If it's a simple select * from table, the data goes straight to the client. If the SQL has some inte ...


有些迷茫啊,我查询10万条数据(一个简单的select语句),难道也直接返回到客户端么?如果所有的结果集直接返回到客户端,那要游标干什么啊?
我原本理解的是:游标中会保存查询结果集的rowid信息,而结果集所需要的数据块被载入到了SGA中,当用户通过游标顺序读取的时候,游标才从SGA的缓存数据块中获取行记录,如果结果集较大或者说需要载入的数据块交多,oracle可能会使用虚拟内存。
请各位牛人帮忙解释一下,我上述描述是否正确?



作者: chicheng_cn421    时间: 2011-10-30 06:42
本帖最后由 chicheng_cn421 于 2011-10-30 06:44 编辑
napolone1983 发表于 2011-10-29 23:59
有些迷茫啊,我查询10万条数据(一个简单的select语句),难道也直接返回到客户端么?如果所有的结果集 ...

应该是这样的:
当语句执行完成之后,查询到的数据还是在服务器进程中,还没有被传送到客户端的用户进程。所以,在服务器端的进程中,有一个专门负责数据提取的一段代码。他的作用就是把查询到的数据结果返回给用户端进程,从而完成整个查询动作。

在我的博客里有一篇收藏的网上的文章,比较详细地分析了Oracle select的整个过程,可以看一下。
【SQL】见微知著 从Select语句看Oracle查询原理(转载)



作者: napolone1983    时间: 2011-10-30 12:19
本帖最后由 napolone1983 于 2011-10-30 12:22 编辑
chicheng_cn421 发表于 2011-10-30 06:42
应该是这样的:
当语句执行完成之后,查询到的数据还是在服务器进程中,还没有被传送到客户端的用户进程 ...


多谢回复!
其实我想知道的是结果集查询出来之后,大数据量的存放以及游标读取的过程(按照OO分析的话,游标包含什么属性,都有哪些方法),而不是整个查询的过程。
各位高手给提供点资料也可以

作者: chicheng_cn421    时间: 2011-10-30 22:10
napolone1983 发表于 2011-10-30 12:19
多谢回复!
其实我想知道的是结果集查询出来之后,大数据量的存放以及游标读取的过程(按照OO分析的话 ...

呵呵,这个我也不是很清楚,期待高人指导
作者: sundog315    时间: 2011-10-31 08:42
对于直接获取的数据,没有必要额外存放,数据已经在那里(buffer cache, logical read/disk,phisical read logical read)
对于中间结果,例如Huang版说的,或者,排序结果、数组之类的,应该在PGA或磁盘中
作者: Yong Huang    时间: 2011-10-31 23:39
> 游标中会保存查询结果集的rowid信息,而结果集所需要的数据块被载入到了SGA中

Of course the data blocks will be scanned into SGA (buffer cache specifically), unless it's a direct path read. Your original question is whether the data will be in PGA. I already answered that. But no matter whether it's select *... or select count(*) ..., the table data must go to the buffer cache first (except for parallel read, and a few other special cases of direct path read).

Yong Huang
作者: chicheng_cn421    时间: 2011-11-1 09:02
本帖最后由 chicheng_cn421 于 2011-11-1 09:06 编辑

学习了^_^



作者: napolone1983    时间: 2011-11-1 09:40
Yong Huang 发表于 2011-10-31 23:39
> 游标中会保存查询结果集的rowid信息,而结果集所需要的数据块被载入到了SGA中

Of course the data blo ...

总觉得各位跟我问的问题有些出入,可能是我描述的不准确,我再精简一下:
(1)相关结果的数据块被载入到了SGA,俺么如果数据量过大(超出了SGA的容量),oracle如何解决?
(2)如果用OO分析的话,游标有哪些属性,哪些方法?或者说游标是如何从数据块中抽取行记录信息的?

请各位高手直接回到我上面的问题就可以了,其他的有时间再请教!!!!!

作者: Yong Huang    时间: 2011-11-2 00:01
It's quite common to have more data fetched than the SGA (buffer cache) can hold. Oracle simply sends the first batch of data to the client, "age out" older blocks in the buffer cache to make room for new blocks, read more blocks from datafiles to cache, and send them to the client.

What is "OO分析"?

Yong Huang
作者: sundog315    时间: 2011-11-2 09:12
OO 面向对象?
作者: napolone1983    时间: 2011-11-2 09:17
本帖最后由 napolone1983 于 2011-11-2 09:20 编辑
Yong Huang 发表于 2011-11-2 00:01
It's quite common to have more data fetched than the SGA (buffer cache) can hold. Oracle simply send ...

非常感谢!!
“面向对象”分析,如果把游标看成一个对象来看的话,他有哪些属性以及哪些方法?


作者: Yong Huang    时间: 2011-11-3 04:02
> 如果把游标看成一个对象来看的话,他有哪些属性以及哪些方法?

You can see properties of a cursor by reading definitions of the columns of v$sql view. Methods that can be applied to a cursor are only a few, open, fetch, execute. Check the procedures in package dbms_sql.

Yong Huang
作者: gclizh    时间: 2011-11-4 17:39
napolone1983 发表于 2011-10-30 12:19
多谢回复!
其实我想知道的是结果集查询出来之后,大数据量的存放以及游标读取的过程(按照OO分析的话 ...

数据从服务器返回到客户端不可能是一个数据包发过去的,肯定分了很多批。
我理解游标的结构可能包含: 指向数据字典相关信息的指针,指向执行计划的指针。每个session  访问这个游标的时候 应该还有 当前执行到什么位置的信息。
作者: Yong Huang    时间: 2011-11-4 23:12
> 数据从服务器返回到客户端不可能是一个数据包发过去的,肯定分了很多批。

Only if the number of rows exceeds array size (called by other name in apps other than sqlplus) set by the client, or exceeds other limits set by SQL*Net. Lower network layer of course also sets packet size.

> 我理解游标的结构可能包含: 指向数据字典相关信息的指针,指向执行计划的指针。每个session  访问这个游标的时候 应该还有 当前执行到什么位置的信息。

A parsed cursor has no pointer pointing to the data dictionary. But there're pointers pointing to addresses in the shared pool.

Actually, we may be talking about two different meanings of cursor. Here I'm talking about the cursor in the library cache of the shared pool. You may be talking about that as in PL/SQL code, "declare cursor ...", or the cursor in dbms_sql. I think the properties are shown by some functions in that package, such as last_row_id, last_row_count, etc.

Yong Huang
作者: 宋夕夕    时间: 2011-12-15 13:15
uga,你要的数据存储在缓冲或者物理文件,缓冲没有的话,会从物理文件fetch到cache,大量数据的话,也一样,看你的共享池子有多大!越大,存的越多!如果不够的话,oracle有相关的内存释放机制,把原先unpin状态占用的,收回来!
作者: 宋夕夕    时间: 2011-12-15 13:16
宋夕夕 发表于 2011-12-15 13:15
uga,你要的数据存储在缓冲或者物理文件,缓冲没有的话,会从物理文件fetch到cache,大量数据的话,也一样, ...

当然还要看你的数量级了!




欢迎光临 ITPUB论坛-专业的IT技术社区 (http://www.itpub.net/) Powered by Discuz! X3.2