老尸 发表于 2015-1-16 22:27:25

MSSQL教程之Fetching Across Commits: Where Is th...

操作被同步到从库上后,则主从都“回天无力”。
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的系统管理上.

爱飞 发表于 2015-2-12 05:15:20

不好!如果出了错;不好调试;不好处理!其实web开发将代码分为3层:web层;业务逻辑层和数据访问层;一般对数据库的操作都在数据访问层来做;这样便于调试和维护!而且将来如果是换了数据库的话;你只需要改数据层的代码;其他层的基本可以不变!要是你在jsp中直接调用sql数据库;那么如果换了数据库呢?岂不都要改?如果报了异常呢?怎么做异常处理?

再见西城 发表于 2015-3-11 07:21:13

其实可以做一下类比,Oracle等数据库产品老早就支持了java编程,而且提供了java池参数作为用户配置接口。但是现在有哪些系统大批使用了java存储过程?!连Oracle自己的应用都不用为什么?!

谁可相欹 发表于 2015-3-17 23:09:15

索引视图2k就有。但是2005对其效率作了一些改进但是schema.viewname的作用域真是太限制了它的应用面。还有一大堆的环境参数和种种限制都让人对它有点却步。

第二个灵魂 发表于 2015-3-25 06:23:44

可能有的朋友会抱怨集成的orderby,其实如果使用ranking函数,Orderby是少不了的。如果担心Orderby会影响效率,可以为orderby的字段建立聚集索引,查询计划会忽略orderby操作(因为本来就是排序的嘛)。
页: [1]
查看完整版本: MSSQL教程之Fetching Across Commits: Where Is th...