📄 select.so
字号:
m4_comment([$Id: select.so,v 10.25 2001/03/31 17:06:27 bostic Exp $])m4_ref_title(Access Methods, Selecting an access method, selecting an @access method, am_conf/intro, am_conf/logrec)m4_p([dnlThe m4_db access method implementation unavoidably interacts with eachapplication's data set, locking requirements and data access patterns.For this reason, one access method may result in dramatically betterperformance for an application than another one. Applications whose datacould be stored using more than one access method may want to benchmarktheir performance using the different candidates.])m4_p([dnlOne of the strengths of m4_db is that it provides multiple access methodswith nearly identical interfaces to the different access methods. Thismeans that it is simple to modify an application to use a different accessmethod. Applications can easily benchmark the different m4_db accessmethods against each other for their particular data set and access pattern.])m4_p([dnlMost applications choose between using the Btree or Hash access methodsor between using the Queue and Recno access methods, because each of thetwo pairs offer similar functionality.])m4_section(Hash or Btree?)m4_p([dnlThe Hash and Btree access methods should be used when logical recordnumbers are not the primary key used for data access. (If logical recordnumbers are a secondary key used for data access, the Btree access methodis a possible choice, as it supports simultaneous access by a key and arecord number.)])m4_p([dnlKeys in Btrees are stored in sorted order and the relationship betweenthem is defined by that sort order. For this reason, the Btree accessmethod should be used when there is any locality of reference among keys.Locality of reference means that accessing one particular key in theBtree implies that the application is more likely to access keys near tothe key being accessed, where "near" is defined by the sort order. Forexample, if keys are timestamps, and it is likely that a request for an8AM timestamp will be followed by a request for a 9AM timestamp, theBtree access method is generally the right choice. Or, for example, ifthe keys are names, and the application will want to review all entrieswith the same last name, the Btree access method is again a good choice.])m4_p([dnlThere is little difference in performance between the Hash and Btreeaccess methods on small data sets, where all, or most of, the data setfits into the cache. However, when a data set is large enough thatsignificant numbers of data pages no longer fit into the cache, thenthe Btree locality of reference described previously becomes importantfor performance reasons. For example, there is no locality of referencefor the Hash access method, and so key "AAAAA" is as likely to be storedon the same database page with key "ZZZZZ" as with key "AAAAB". In theBtree access method, because items are sorted, key "AAAAA" is far morelikely to be near key "AAAAB" than key "ZZZZZ". So, if the applicationexhibits locality of reference in its data requests, then the Btree pageread into the cache to satisfy a request for key "AAAAA" is much morelikely to be useful to satisfy subsequent requests from the applicationthan the Hash page read into the cache to satisfy the same request.This means that for applications with locality of reference, the cacheis generally much more effective for the Btree access method than theHash access method, and the Btree access method will make many fewerI/O calls.])m4_p([dnlHowever, when a data set becomes even larger, the Hash access method canoutperform the Btree access method. The reason for this is that Btreescontain more metadata pages than Hash databases. The data set can growso large that metadata pages begin to dominate the cache for the Btreeaccess method. If this happens, the Btree can be forced to do an I/Ofor each data request because the probability that any particular datapage is already in the cache becomes quite small. Because the Hash accessmethod has fewer metadata pages, its cache stays "hotter" longer in thepresence of large data sets. In addition, once the data set is so largethat both the Btree and Hash access methods are almost certainly doingan I/O for each random data request, the fact that Hash does not have towalk several internal pages as part of a key search becomes a performanceadvantage for the Hash access method as well.])m4_p([dnlApplication data access patterns strongly affect all of these behaviors,for example, accessing the data by walking a cursor through the databasewill greatly mitigate the large data set behavior describe above becauseeach I/O into the cache will satisfy a fairly large number of subsequentdata requests.])m4_p([dnlIn the absence of information on application data and data accesspatterns, for small data sets either the Btree or Hash access methodswill suffice. For data sets larger than the cache, we normally recommendusing the Btree access method. If you have truly large data, then theHash access method may be a better choice. The m4_ref(db_stat) utilityis a useful tool for monitoring how well your cache is performing.])m4_section(Queue or Recno?)m4_p([dnlThe Queue or Recno access methods should be used when logical recordnumbers are the primary key used for data access. The advantage of theQueue access method is that it performs record level locking and for thisreason supports significantly higher levels of concurrency than the Recnoaccess method. The advantage of the Recno access method is that itsupports a number of additional features beyond those supported by theQueue access method, such as variable-length records and support forbacking flat-text files.])m4_p([dnlLogical record numbers can be mutable or fixed: mutable, where logicalrecord numbers can change as records are deleted or inserted, and fixed,where record numbers never change regardless of the database operation.It is possible to store and retrieve records based on logical recordnumbers in the Btree access method. However, those record numbers arealways mutable, and as records are deleted or inserted, the logical recordnumber for other records in the database will change. The Queue accessmethod always runs in fixed mode, and logical record numbers never changeregardless of the database operation. The Recno access method can beconfigured to run in either mutable or fixed mode.])m4_p([dnlIn addition, the Recno access method provides support for databases whosepermanent storage is a flat text file and the database is used as a fast,temporary storage area while the data is being read or modified.])m4_page_footer
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -