select count(*) from tab1 要11秒以上指示!!!??? 表有主键吗?把select count(*) from tab1 换成select count(主键列) from tab1 就好了。 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 select count(1) from tab1 libin_ftsafe(子陌红尘:当libin告别ftsafe) ( ) 只能重建表了吗?是表损坏了?tomhuang(春城) ( ) 和 billhepeng(过路客) ( ) 你们的提议没用,效果是一样的。而且我要不是做这个count的快慢,现在明显是'表'有问题 DBCC CHECKTABLE ('tbname') DBCC CHECKTABLE看看是否有错误然后DBCC SHOWCONTIG看看这个表是否有索引碎片,如果碎片很严重,使用DBCC INDEXDEFRAG整理碎片 select rows from sysindexes where id = object_id('tab1') and indid < 2 DBCC CHECKTABLE 没发现有错误DBCC SHOWCONTIG:DBCC SHOWCONTIG scanning 'tab1' table...Table: 'tab1' (98099390); index ID: 1, database ID: 7TABLE level scan performed.- Pages Scanned................................: 1252730- Extents Scanned..............................: 156851- Extent Switches..............................: 156854- Avg. Pages per Extent........................: 8.0- Scan Density [Best Count:Actual Count].......: 99.83% [156592:156855]- Logical Scan Fragmentation ..................: 0.01%- Extent Scan Fragmentation ...................: 12.22%- Avg. Bytes Free per Page.....................: 7219.0- Avg. Page Density (full).....................: 10.81%DBCC execution completed. If DBCC printed error messages, contact your system administrator.请问这样的结果正常吧? DBCC SHOWCONTIG的结果还好看看执行计划,是否用到了聚集索引 有聚集索引: 自动编号 ID - int 数据库文件放在cluster上的,log和data文件不同分区上,硬盘dell检查过正常的.我现在想重建表,这个表关系着三个表,就是有外键.如果新建好表后,数据导回来前是不是要拿掉外键?这个自动编号的ID导入前关闭自动编号,导回数据后再设成自动编号会不会有影响? 同意luoqun_ncs(暂时冰封)所说。碰到问题不要急着想办法避开,找找原因先。 select count(*) from tb1select count(*) from 另一个表比较一下他俩的执行计划和成本比较一下他俩估计的执行计划和成本 关注.1100多W,如果没有预读过,count一下要多久?谁能告诉我? 请大家再帮忙分析以下数据:tab1在实时数据库上的Execution plan:Estimated Row Count: 11898302Estimated Row Size: 37Estimated I/O cost: 151Estimated CPU cost: 6.54Estimated Number of executes: 1.0Estimated cost: 157.083910 (100%)Estimated Subtree cost: 157tab1在同步数据库上的Execution plan:Estimated Row Count: 11898302Estimated Row Size: 37Estimated I/O cost: 16.4Estimated CPU cost: 6.54Estimated Number of executes: 1.0Estimated cost: 22.944778 (97%)Estimated Subtree cost: 22.9I/O Cost 差异????? 表碎片的问题,用dbcc shrinkdatabase(dbname)試一下 晕,重建一下索引,DBCC DBREINDEX 使用 sp_spaceused tablename 返回值有 rows msmis() :再选择那些重复记录比较多得作为聚集索引,效果就会很好//恰恰相反,效果会很差的;如果某个字段只有0\1这2个值,1千万数据,效率相当差 LZ,I如果索引确实重新建过,I/O差距这么大,估计和服务器的硬件配置有关系了再试试在实时数据库新建一个数据库,把千万数据重新组织成一个新表,再看看count的效率; 问题就在索引上有问题的表:DBCC SHOWCONTIG Avg. Page Density (full).....................: 10.81%--平均页的密度才10%你同步表的DBCC SHOWCONTIG 信息呢? 同步表的DBCC SHOWCONTIG 信息:DBCC SHOWCONTIG scanning 'tab1' table...Table: 'tab1' (98099390); index ID: 1, database ID: 7TABLE level scan performed.- Pages Scanned................................: 152871- Extents Scanned..............................: 19178- Extent Switches..............................: 19219- Avg. Pages per Extent........................: 8.0- Scan Density [Best Count:Actual Count].......: 99.42% [19109:19220]- Logical Scan Fragmentation ..................: 0.09%- Extent Scan Fragmentation ...................: 13.13%- Avg. Bytes Free per Page.....................: 55.8- Avg. Page Density (full).....................: 99.31%DBCC execution completed. If DBCC printed error messages, contact your system administrator. 问题很明显了,有问题的表:- Pages Scanned................................: 1252730同步表:- Pages Scanned................................: 1528718倍的数据页感觉还是填充因子的问题,别的问题想不到了 select count(1) from td要有主键 生成交叉报表样式的数据,sql语句怎么写 SQL SERVER Cpu使用情况~! 探讨一下:可以写成一句的SQL语句,是否有必要写成存储过程? 如何赋予用户创建数据表但没有drop数据表的权限 求sql 请教个问题关于NULL空值的判断 怎样把varchar转换为numeric? 征询数据库设计方案 奇怪呀? 出现错误"Cannot resolve collation conflict for equal to operation.",请问可能是什么原因? sql server安装问题。 SQL语句优化-----请大哥大姐们帮忙?
你们的提议没用,效果是一样的。而且我要不是做这个count的快慢,现在明显是'表'有问题
DBCC SHOWCONTIG scanning 'tab1' table...
Table: 'tab1' (98099390); index ID: 1, database ID: 7
TABLE level scan performed.
- Pages Scanned................................: 1252730
- Extents Scanned..............................: 156851
- Extent Switches..............................: 156854
- Avg. Pages per Extent........................: 8.0
- Scan Density [Best Count:Actual Count].......: 99.83% [156592:156855]
- Logical Scan Fragmentation ..................: 0.01%
- Extent Scan Fragmentation ...................: 12.22%
- Avg. Bytes Free per Page.....................: 7219.0
- Avg. Page Density (full).....................: 10.81%
DBCC execution completed. If DBCC printed error messages, contact your system administrator.请问这样的结果正常吧?
我现在想重建表,这个表关系着三个表,就是有外键.
如果新建好表后,数据导回来前是不是要拿掉外键?这个自动编号的ID导入前关闭自动编号,导回数据后再设成自动编号会不会有影响?
select count(*) from 另一个表比较一下他俩的执行计划和成本
比较一下他俩估计的执行计划和成本
关注.
1100多W,如果没有预读过,count一下要多久?谁能告诉我?
tab1在实时数据库上的Execution plan:
Estimated Row Count: 11898302
Estimated Row Size: 37
Estimated I/O cost: 151
Estimated CPU cost: 6.54
Estimated Number of executes: 1.0
Estimated cost: 157.083910 (100%)
Estimated Subtree cost: 157tab1在同步数据库上的Execution plan:
Estimated Row Count: 11898302
Estimated Row Size: 37
Estimated I/O cost: 16.4
Estimated CPU cost: 6.54
Estimated Number of executes: 1.0
Estimated cost: 22.944778 (97%)
Estimated Subtree cost: 22.9I/O Cost 差异?????
DBCC DBREINDEX
再选择那些重复记录比较多得作为聚集索引,效果就会很好//恰恰相反,效果会很差的;如果某个字段只有0\1这2个值,1千万数据,效率相当差
在实时数据库新建一个数据库,把千万数据重新组织成一个新表,再看看count的效率;
有问题的表:DBCC SHOWCONTIG
Avg. Page Density (full).....................: 10.81%
--平均页的密度才10%
你同步表的DBCC SHOWCONTIG 信息呢?
DBCC SHOWCONTIG scanning 'tab1' table...
Table: 'tab1' (98099390); index ID: 1, database ID: 7
TABLE level scan performed.
- Pages Scanned................................: 152871
- Extents Scanned..............................: 19178
- Extent Switches..............................: 19219
- Avg. Pages per Extent........................: 8.0
- Scan Density [Best Count:Actual Count].......: 99.42% [19109:19220]
- Logical Scan Fragmentation ..................: 0.09%
- Extent Scan Fragmentation ...................: 13.13%
- Avg. Bytes Free per Page.....................: 55.8
- Avg. Page Density (full).....................: 99.31%
DBCC execution completed. If DBCC printed error messages, contact your system administrator.
有问题的表:
- Pages Scanned................................: 1252730
同步表:
- Pages Scanned................................: 152871
8倍的数据页感觉还是填充因子的问题,别的问题想不到了