电信主站 网通分站
购买流程 付款方式 常见问题 在线提问 续租服务 购物车
用户名: 密 码: 忘记密码?
首 页
域名注册
虚拟主机
双线主机
服务器租用
VPS主机
企业邮局
代理专区
客服中心
虚拟主机行业资讯 虚拟主机评测对比 互联网最新动态 技术学院 站长资讯 在线教程 网站运营
搜索优化 服务器 网络编程 图形图象 站长之家 网页制作 操作系统
冲浪宝典 软件教学 视频通信 办公软件 邮件系统 网络安全 认证考试
您当前位置:西部数码->资讯中心-> 在线教程-> 数据库
Heaps of data: tables without clustered indexes-数据库专栏,SQL Server
作者:网友供稿 点击:9
  西部数码-全国虚拟主机10强!20余项虚拟主机管理功能,全国领先!第6代双线路虚拟主机,南北访问畅通无阻!虚拟主机可在线rar解压,自动数据恢复设置虚拟目录等.虚拟主机免费赠送访问统计,企业邮局.Cn域名注册10元/年,自助建站480元起,免费试用7天,满意再付款!P4主机租用799元/月.月付免压金!
文章页数:[1] 

if you create a table on adaptive server, but do not create a clustered index, the table is stored as a heap. the data rows are not stored in any particular order. this section describes how select, insert, delete, and update operations perform on heaps when there is no "useful" index to aid in retrieving data.

the phrase "no useful index" is important in describing the optimizers decision to perform a table scan. sometimes, an index exists on the columns named in a where clause, but the optimizer determines that it would be more costly to use the index than to perform a table scan.

other chapters in this book describe how the optimizer costs queries using indexes and how you can get more information about why the optimizer makes these choices.

table scans are always used when you select all rows in a table. the only exception is when the query includes only columns that are keys in a nonclustered index.

for more information, see "index covering".

the following sections describe how adaptive server locates rows when a table has no useful index.
lock schemes and differences between heaps
the data pages in an allpages-locked table are linked into a doubly-linked list of pages by pointers on each page. pages in data-only-locked tables are not linked into a page chain.

in an allpages-locked table, each page stores a pointer to the next page in the chain and to the previous page in the chain. when new pages need to be inserted, the pointers on the two adjacent pages change to point to the new page. when adaptive server scans an allpages-locked table, it reads the pages in order, following these page pointers.

pages are also doubly-linked at each index level of allpages-locked tables, and the leaf level of indexes on data-only-locked tables. if an allpages-locked table is partitioned, there is one page chain for each partition.

another difference between allpages-locked tables and data-only-locked tables is that data-only-locked tables use fixed row ids. this means that row ids (a combination of the page number and the row number on the page) do not change in a data-only-locked table during normal query processing.

row ids change only when one of the operations that require data-row copying is performed, for example, during reorg rebuild or while creating a clustered index.

for information on how fixed row ids affect heap operations, see "deleting from a data-only locked heap table" and "data-only-locked heap tables".
select operations on heaps
when you issue a select query on a heap, and there is no useful nonclustered index, adaptive server must scan every data page in the table to find every row that satisfies the conditions in the query. there may be one row, many rows, or no rows that match.
allpages-locked heap tables
for allpages-locked tables, adaptive server reads the first column in sysindexes for the table, reads the first page into cache, and follows the next page pointers until it finds the last page of the table.
data-only locked heap tables
since the pages of data-only-locked tables are not linked in a page chain, a select query on a heap table uses the tables oam and the allocation pages to locate all the rows in the table. the oam page points to the allocation pages, which point to the extents and pages for the table.
inserting data into an allpages-locked heap table
when you insert data into an allpages-locked heap table, the data row is always added to the last page of the table. if there is no clustered index on a table, and the table is not partitioned, the sysindexes.root entry for the heap table stores a pointer to the last page of the heap to locate the page where the data needs to be inserted.

if the last page is full, a new page is allocated in the current extent and linked onto the chain. if the extent is full, adaptive server looks for empty pages on other extents being used by the table. if no pages are available, a new extent is allocated to the table.
conflicts during heap inserts
one of the severe performance limits on heap tables that use allpages locking is that the page must be locked when the row is added, and that lock is held until the transaction completes. if many users are trying to insert into an allpages-locked heap table at the same time, each insert must wait for the preceding transaction to complete.

this problem of last-page conflicts on heaps is true for:
single row inserts using insert

multiple row inserts using select into or insert...select, or several insert statements in a batch

bulk copy into the table



some workarounds for last-page conflicts on heaps include:
switching to datapages or datarows locking

creating a clustered index that directs the inserts to different pages

partitioning the table, which creates multiple insert points for the table, giving you multiple "last pages" in an allpages-locked table



other guidelines that apply to all transactions where there may be lock conflicts include:
keeping transactions short

avoiding network activity and user interaction whenever possible, once a transaction acquires locks


inserting data into a data-only-locked heap table
when users insert data into a data-only-locked heap table, adaptive server tracks page numbers where the inserts have recently occurred, and keeps the page number as a hint for future tasks that need space. subsequent inserts to the table are directed to one of these pages. if the page is full, adaptive server allocates a new page and replaces the old hint with the new page number.

blocking while many users are simultaneously inserting data is much less likely to occur during inserts to data-only-locked heap tables. when blocking occurs, adaptive server allocates a small number of empty pages and directs new inserts to those pages using these newly allocated pages as hints.

for datarows-locked tables, blocking occurs only while the actual changes to the data page are being written; although row locks are held for the duration of the transaction, other rows can be inserted on the page. the row-level locks allow multiple transaction to hold locks on the page.

there may be slight blocking on data-only-locked tables, because adaptive server allows a small amount of blocking after many pages have just been allocated, so that the newly allocated pages are filled before additional pages are allocated.
if conflicts occur during heap inserts
conflicts during inserts to heap tables are greatly reduced for data-only-locked tables, but can still take place. if these conflicts slow inserts, some workarounds can be used, including:
switching to datarows locking, if the table uses datapages locking

using a clustered index to spread data inserts

partitioning the table, which provides additional hints and allows new pages to be allocated on each partition when blocking takes place


deleting data from a heap table
when you delete rows from a heap table, and there is no useful index, adaptive server scans the data rows in the table to find the rows to delete. it has no way of knowing how many rows match the conditions in the query without examining every row.
deleting from an allpages-locked heap table
when a data row is deleted from a page in an allpages-locked table, the rows that follow it on the page move up so that the data on the page remains contiguous.
deleting from a data-only locked heap table
when you delete rows from a data-only-locked heap table, a table scan is required if there is no useful index. the oam and allocation pages are used to locate the pages.

the space on the page is not recovered immediately. rows in data-only-locked tables must maintain fixed row ids, and need to be reinserted in the same place if the transaction is rolled back.

after a delete transaction completes, one of the following processes shifts rows on the page to make the space usage contiguous:
the housekeeper process

an insert that needs to find space on the page

the reorg reclaim_space command


deleting the last row on a page
if you delete the last row on a page, the page is deallocated. if other pages on the extent are still in use by the table, the page can be used again by the table when a page is needed.

if all other pages on the extent are empty, the entire extent is deallocated. it can be allocated to other objects in the database. the first data page for a table or an index is never deallocated.
updating data on a heap table
like other operations on heaps, an update that has no useful index on the columns in the where clause performs a table scan to locate the rows that need to be changed.
allpages-locked heap tables
updates on allpages-locked heap tables can be performed in several ways:
if the length of the row does not change, the updated row replaces the existing row, and no data moves on the page.

if the length of the row changes, and there is enough free space on the page, the row remains in the same place on the page, but other rows move up or down to keep the rows contiguous on the page.

the row offset pointers at the end of the page are adjusted to point to the changed row locations.

if the row does not fit on the page, the row is deleted from its current page, and the "new" row is inserted on the last page of the table.

this type of update can cause a conflict on the last page of the heap, just as inserts do. if there are any nonclustered indexes on the table, all index references to the row need to be updated.


data-only-locked heap tables
one of the requirements for data-only-locked tables is that the row id of a data row never changes (except during intentional rebuilds of the table). therefore, updates to data-only-locked tables can be performed by the first two methods described above, as long as the row fits on the page.

but when a row in a data-only-locked table is updated so that it no longer fits on the page, a process called row forwarding performs the following steps:
the row is inserted onto a different page, and

a pointer to the row id on the new page is stored in the original location for the row.



indexes do not need to be modified when rows are forwarded. all indexes still point to the original row id.

if the row needs to be forwarded a second time, the original location is updated to point to the new page--the forwarded row is never more than one hop away from its original location.

row forwarding increases concurrency during update operations because indexes do not have to be updated. it can slow data retrieval, however, because a task needs to read the page at the original location and then read the page where the forwarded data is stored.

forwarded rows can be cleared from a table using the reorg command.

for more information on updates, see "how update operations are performed".

文章整理:西部数码--专业提供域名注册虚拟主机服务
http://www.west263.com
以上信息与文章正文是不可分割的一部分,如果您要转载本文章,请保留以上信息,谢谢!
相关主题
文章页数:[1] 
Google
热门文章
·数据库开发个人总结(ADO.NET小结)-.NET教程,数据库应用
·怎么由DataSet将数据导入Excel?-.NET教程,数据库应用
·动态创建SQL Server数据库、表、存储过程-ASP教程,数据库相关
·Win32环境下动态链接库(DLL)编程原理-.NET教程,数据库应用
·封装的ADO.NET对数据库操作经典类-.NET教程,数据库应用
·在DataGridView中获得DataGridViewCheckBoxColumn的状态-ASP教程,数据库相关
·DataGrid使用心得(附大量代码)-ASP教程,数据库相关
·用代码创建DataGrid的多链接及checkbox事件响应-.NET教程,数据库应用
·ADO.NET 的最佳实践技巧-.NET教程,数据库应用
·转载: 用纯ASP代码实现图片上传并存入数据库中

最新文章
·根据数据表中数据,生成Powerpoint幻灯片-ASP教程,数据库相关
·DataGrid中的按钮反选事件与NamingContainer(命名容器)-downmoon-ASP教程,数据库相关
·使用用VB处理MYSQL数据库中二进制数据问题-.NET教程,VB.Net语言
·关于DataGridView中如何接收处于编辑状态下的当前信息-ASP教程,数据库相关
·在DataGridView中获得DataGridViewCheckBoxColumn的状态-ASP教程,数据库相关
·.net下访问Access数据库需要注意的问题-.NET教程,Asp.Net开发
·ActiveMQ4.1+Spring2.0的POJO JMS方案(上)-.NET教程,数据库应用
·ASP.NET 2.0中直接将Access数据库导入到Excel文件中-.NET教程,Asp.Net开发
·NET(C#)连接各类数据库-集锦-.NET教程,C#语言
·ASP.NET2.0连接SQL Server数据库详解-.NET教程,Asp.Net开发


 
 


版权申明:本站文章均来自网络,如有侵权,请联系我们,我们收到后立即删除,谢谢!

特别注意:本站所有转载文章言论不代表本站观点,本站所提供的摄影照片,插画,设计作品,如需使用,请与原作者联系,版权归原作者所有。
  打印  刷新  关闭
返回首页 |关于我们 | 联系我们 | 付款方式 | 创业联盟 | 虚拟主机 | 资讯中心 | 友情链接 | 网站地图

版权所有 西部数码(www.west263.com)
CopyRight (c) 2002~2006 west263.com all right reserved.
公司地址:四川成都市万和路90号天象大厦4楼 邮编:610031
电话总机:028-86262244 86263048 86263408 86263960 86264018 86267838
售前咨询:总机转201 202 203 204 206 208
售后服务:总机转211 212 213 214
财务咨询:总机转224 223 传真:028-86264041 财务QQ:点击发送消息给对方635483282
售前咨询QQ:点击发送消息给对方2182518 点击发送消息给对方241975952 点击发送消息给对方275026793 点击发送消息给对方408235859
售后服务QQ:点击发送消息给对方17708515 点击发送消息给对方307742704 点击发送消息给对方287976517 点击发送消息给对方363783715
《中华人民共和国增值电信业务经营许可证》编号:川B2-20030065号