仓酷云

 找回密码
 立即注册
搜索
热搜: 活动 交友 discuz
查看: 886|回复: 7
打印 上一主题 下一主题

[学习教程] MSSQL教程之Fetching Across Commits: Where Is th...

[复制链接]
老尸 该用户已被删除
跳转到指定楼层
楼主
发表于 2015-1-16 22:27:25 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式

马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。

您需要 登录 才可以下载或查看,没有帐号?立即注册

x
操作被同步到从库上后,则主从都“回天无力”。
FetchingAcrossCommits:WhereIstheSourceoftheProblem?

ByBorisMilrud

FetchingacrosscommitsisacommonandacceptedpracticeintheOracleprogrammingworld.However,itisnotanANSI-supportedoperation.AccordingtotheANSIstandard,acursorisinvalidatedwheneveracommitisperformed,whichmeansitshouldbeclosedandreopened.Hence,youshouldbeawareofpotentialORA-01555errorsandthefactthatyouarerelyingonacursorbehaviorthatisnottotheANSIstandard.

Oraclealwaysenforcesstatement-levelreadconsistency.Thisguaranteesthatthedatareturnedbyasinglequeryisconsistentwithrespecttothetimewhenthequerybegan.Therefore,aqueryneverseesthedatachangesmadebythetransactionsthatcommitduringthecourseofaquerysexecution.
AsIdescribedinmyprevious10-MinuteSolutiononthissubject,Oracleuniquelyidentifiesanygivenpointintimebyasetofnumbers,calledtheSystemChangeNumbers.Toensurereadconsistency,OraclemarksthecurrentSCNasthequeryenterstheexecutionphase.Thequerycanseethesnapshotoftherecordsonlyastheywereatthetimethattheyweremarkedby,orassignedto,theSCN.
Thisisthesituationwhenaqueryopensacursor,thenloopsthroughfetching,changing,andcommittingtherecordsonthesametable.Thecursorrequiresa"snapshot"ofthedataatthecursorsopentimeforreadconsistency.AsdatablocksarereadonbehalfofthequeryandeachblockcontainsuncommittedchangesofothertransactionsorchangeddatawithmorerecentSCNs,thedataisthenreconstructedusingthesavedsnapshotfromtherollbacksegments.Duringalong-runningquery,undoentriesintherollbacksegmentmaygetoverwrittenbyanothertransaction,evenfromthesamequery.Inthiscase,theOracleserverwouldbeunabletoreconstructthesnapshot,resultingintheORA-01555error.
Heresanexample:AcursorisopenedatSCN=10.TheexecutionSCNofthequeryisthenmarkedasSCN=10.Everyfetchbythatcursornowneedstogettheread-consistentdatafromSCN=10.Codeinthestoredprocedureisfetchingrecordsfromthecursor,changingthem,andcommittingthem.LetssaytheywerecommittedwithSCN=20.Ifalaterfetchhappenstoretrievearecordthatsinoneofthepreviouslycommittedblocks,thenthefetchwillseethatthecurrentblockSCNis20.BecausethefetchhastogetthesnapshotfromSCN=10itwilltrytofinditintherollbacksegments.Ifitcanrollsufficientlybackaspreviouslyexplained,thenitwillbeabletoreconstructthesnapshotfromSCN=10.Ifnot,itwillreturntheORA-01555error.
Committinglessoften,thuscreatinglargerrollbacksegments,willreducetheprobabilityofgettingthiserror.TheonlydrawbacktothisisthatthedeveloperhastocontacttheDBAandmakesuretherollbacksegmentscanbeextended,andthattherollbacktablespacecanaccommodatethem.

读这类文章仍是有劳绩的。让你分明一些事变。
有了数据以后,我们就要想一个比较统一的方法来闪回。上面我们说了对于DML操作,可以通过反向执行所有逆操作来实现,对于语句里面的DDL,只能直接跳过。原因是一个DDL不一定有直接的逆操作。
灵魂腐蚀 该用户已被删除
沙发
发表于 2015-1-19 13:07:29 | 只看该作者
这是一个不错的新特性。虽然索引的附加字段没有索引键值效率高,但是相对映射到数据表中效率还是提高了很多。我做过试验,在我的实验环境中会比映射到表中提高30%左右的效率。
若相依 该用户已被删除
板凳
发表于 2015-1-27 23:36:07 | 只看该作者
光写几个SQL实在叫无知。
飘灵儿 该用户已被删除
地板
发表于 2015-2-5 14:18:01 | 只看该作者
SQL语言是学习所有数据库产品的基础,无论你是做数据库管理还是做数据库开发都是这样。不过具体学习的侧重点要看你将来做哪一块,如果是做数据库管理(DBA),侧重点应该放在SQLServer的系统管理上.
爱飞 该用户已被删除
5#
发表于 2015-2-12 05:15:20 | 只看该作者
不好!如果出了错;不好调试;不好处理!其实web开发将代码分为3层:web层;业务逻辑层和数据访问层;一般对数据库的操作都在数据访问层来做;这样便于调试和维护!而且将来如果是换了数据库的话;你只需要改数据层的代码;其他层的基本可以不变!要是你在jsp中直接调用sql数据库;那么如果换了数据库呢?岂不都要改?如果报了异常呢?怎么做异常处理?
再见西城 该用户已被删除
6#
发表于 2015-3-11 07:21:13 | 只看该作者
其实可以做一下类比,Oracle等数据库产品老早就支持了java编程,而且提供了java池参数作为用户配置接口。但是现在有哪些系统大批使用了java存储过程?!连Oracle自己的应用都不用为什么?!
谁可相欹 该用户已被删除
7#
发表于 2015-3-17 23:09:15 | 只看该作者
索引视图2k就有。但是2005对其效率作了一些改进但是schema.viewname的作用域真是太限制了它的应用面。还有一大堆的环境参数和种种限制都让人对它有点却步。
第二个灵魂 该用户已被删除
8#
发表于 2015-3-25 06:23:44 | 只看该作者
可能有的朋友会抱怨集成的orderby,其实如果使用ranking函数,Orderby是少不了的。如果担心Orderby会影响效率,可以为orderby的字段建立聚集索引,查询计划会忽略orderby操作(因为本来就是排序的嘛)。
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

QQ|Archiver|手机版|仓酷云 鄂ICP备14007578号-2

GMT+8, 2024-5-3 20:30

Powered by Discuz! X3.2

© 2001-2013 Comsenz Inc.

快速回复 返回顶部 返回列表