显示标签为“speed”的博文。显示所有博文
显示标签为“speed”的博文。显示所有博文

2012年3月19日星期一

FK Position

Does it make any difference where we define the FKs in a table? I mean, do I speed up the query if I define it as the second field or the last one? What about the other fields, the ones that are not FKs, but are used as filters in a query?

Raul:

In general, none of this makes much practical difference to speed of execution. The two things that do matter are (1) do you have indexes on the foreign table in place that correspond to your foreign key and (2) does use of that index with a specific query also require a bookmark lookup for that specific query. If the foreign key has a correspondence to the clustered index of the other table -- and that is often the case -- then no bookmark lookup is necessary. If the foreign key has correspondence to a non-clustered index of the other table but there are fields in the other table that are referenced and are not part of the non-clustered index then a bookmark lookup will be necessary.

If a query references only a short list of records then the non-clustered index will often get used to optimize the query. However, if the query references a very large number of records in the foreign table the optimizer may "decide" that the cost of performing the random reads necessary to support bookmark lookups is too high. In these circumstances the optimizer will often opt to perform a table scan of the foreign table instead of of an index seek.

Bleah. Somebody please say this in a better way.

|||

Column position is virtually meaningless in defining PK's.

Column position is virtually menaingless except:

1. In UNIQUE and PRIMARY key constraints, and all indexes, order of columns has meaning.

2. In relatively rare cases, order of column conditions in a WHERE clause is involved (and only when the criteria is so large as to make it impossible for SQL Server to check all possible uses in a timely manner)

The position of a column in a table has no little if any bearing on performance, as it is just a representation of what is physically implemented in bits and bytes down in the physical table. If it were advantageous to reorganize the data on the page, the data could be reorganized by the storage engine without you knowing. So rest easy, it should make no difference at all.

Fixing my table based on Dbcc Showcontig results

Can someone please help me interpret this result set below and suggest
on way I can speed up my table? What changes should I make?

DBCC SHOWCONTIG scanning 'tblListing' table...
Table: 'tblListing' (1092914965); index ID: 1, database ID: 13
TABLE level scan performed.
- Pages Scanned........................: 97044
- Extents Scanned.......................: 12177
- Extent Switches.......................: 13452
- Avg. Pages per Extent..................: 8.0
- Scan Density [Best Count:Actual Count]......: 90.17% [12131:13453]
- Logical Scan Fragmentation ..............: 0.86%
- Extent Scan Fragmentation ...............: 2.68%
- Avg. Bytes Free per Page................: 1415.8
- Avg. Page Density (full)................: 82.51%
DBCC execution completed. If DBCC printed error messages, contact your
system administrator.

Thank you.You should take a look at ttp://www.microsoft.com/technet/prodtechnol/sql/2000/maintain/ss2kidbp.mspx. Let us know if you have any questions after reading this. Keep in mind that it's quite possible that given your server workload, index defragmentation isn't at all necessary.

Thanks,
Ryan Stonecipher
Microsoft SQL Server Storage Engine.
"SR" <yosonu@.socal.rr.com> wrote in message news:ba4c21f6.0406140740.7de00c3a@.posting.google.c om...
Can someone please help me interpret this result set below and suggest
on way I can speed up my table? What changes should I make?

DBCC SHOWCONTIG scanning 'tblListing' table...
Table: 'tblListing' (1092914965); index ID: 1, database ID: 13
TABLE level scan performed.
- Pages Scanned........................: 97044
- Extents Scanned.......................: 12177
- Extent Switches.......................: 13452
- Avg. Pages per Extent..................: 8.0
- Scan Density [Best Count:Actual Count]......: 90.17% [12131:13453]
- Logical Scan Fragmentation ..............: 0.86%
- Extent Scan Fragmentation ...............: 2.68%
- Avg. Bytes Free per Page................: 1415.8
- Avg. Page Density (full)................: 82.51%
DBCC execution completed. If DBCC printed error messages, contact your
system administrator.

Thank you.|||"SR" <yosonu@.socal.rr.com> wrote in message
news:ba4c21f6.0406140740.7de00c3a@.posting.google.c om...
> Can someone please help me interpret this result set below and suggest
> on way I can speed up my table? What changes should I make?
> DBCC SHOWCONTIG scanning 'tblListing' table...
> Table: 'tblListing' (1092914965); index ID: 1, database ID: 13
> TABLE level scan performed.
> - Pages Scanned........................: 97044
> - Extents Scanned.......................: 12177
> - Extent Switches.......................: 13452
> - Avg. Pages per Extent..................: 8.0
> - Scan Density [Best Count:Actual Count]......: 90.17% [12131:13453]
> - Logical Scan Fragmentation ..............: 0.86%
> - Extent Scan Fragmentation ...............: 2.68%
> - Avg. Bytes Free per Page................: 1415.8
> - Avg. Page Density (full)................: 82.51%
> DBCC execution completed. If DBCC printed error messages, contact your
> system administrator.
> Thank you.

http://www.sql-server-performance.c..._showcontig.asp

At first glance, the output seems fine - there is very little fragmentation,
and the scan density is high. If you're having performance issues with this
table, you may want to give some more information. In particular, the CREATE
TABLE and CREATE INDEX statements, plus a query which is performing badly,
and the reason why you believe this table is the problem (eg. the execution
plan for the query).

Simon