The old sysindexes table (as of 2005 implemented as a compatibility view) has a useful column named keycnt. This is supposed to give us the number of columns (keys) in the index. However, to make heads and tails out of the numbers, we need to understand how a non-clustered index is constructed. For a heap, the pointer to a row is the physical file/page/row address (aka “rowid”). This is counted as a key in the keycnt column:
IF OBJECT_ID('t1') IS NOT NULL DROP TABLE t1
GO
CREATE TABLE T1 (c1 INT, c2 datetime, c3 VARCHAR(3))
CREATE INDEX ix_T1_c1 ON T1 (c1)
CREATE INDEX ix_T1_c1_c2 ON T1 (c1, c2)
CREATE INDEX ix_T1_c1_c2_c3 ON T1 (c1, c2, c3)
CREATE INDEX ix_T1_c2 ON T1 (c2)
SELECT name, keycnt, indid, id
FROM sys.sysindexes
WHERE id = OBJECT_ID('T1')
For the index on column (c2), you see a keycnt of 2. This is the key in the index plus the rowid.
For a nonclustered index on a clustered table, the row locator is the clustering key. Note, though, that if the clustered index is not defined as unique (PK, UQ etc), then another “uniqueifier” key/column is added. Building on above example:
CREATE UNIQUE CLUSTERED INDEX ix_T1_c1 ON T1 (c1) WITH DROP_EXISTING
SELECT name, keycnt, indid, id
FROM sys.sysindexes
WHERE id = OBJECT_ID('T1')
GO
CREATE CLUSTERED INDEX ix_T1_c1 ON T1 (c1) WITH DROP_EXISTING
SELECT name, keycnt, indid, id
FROM sys.sysindexes
WHERE id = OBJECT_ID('T1')
Consider the (non-clustered) index on column c2. For the first one, where the table has a unique clustered index, we see a keycnt of 2, the column c2 plus the clustered key. But when we define the clustered index as non-unique, we see +1 for the keycnt column; the uniqueifier. The uniqueifier is 4 byte, and only populated for rows which are duplicates of an existing clustered key (i.e. no extra cost if no duplicates).
But we want to stay away from compatibility views, right? Since we no longer have a key count column in sys.indexes, we need to grab that from sys.index_columns. This do not, however include the internal columns, only the explicitly defined columns:
SELECT
i.name
,i.index_id
,(SELECT COUNT(*)
FROM sys.index_columns AS ic
WHERE i.OBJECT_ID = ic.OBJECT_ID
AND i.index_id = ic.index_id) AS keycnt
FROM sys.indexes AS i
WHERE OBJECT_ID = OBJECT_ID('T1')
Been messing around on a5game lately. It’s got a few interesting things going on. Could be a good shout if you’re looking for something new a5game.
VN888game does it again! Smooth gameplay, fast payouts– what more could you ask for? My trusted site and it could be yours. Get started with vn888game
Golden Hoyeah Slots? Those slots are seriously addictive! The bonuses hit frequently, and the graphics are really vibrant. Definitely a time-killer if you enjoy spinning the reels. So fun go try! goldenhoyeahslots
Lakiwinph is pretty good, have a lot of fun games they are quick to load and the support is pretty decent too. Recommend giving Lakiwinph a shot! lakiwinph
Yo, 5sbet1 is legit, man! Found some solid games and the payouts were smooth. Definitely gonna hit it up again. Check it out here: 5sbet1
Alright alright alright! 5sbetwin surprised me, honestly. Good selection and the site’s easy to navigate. Give it a whirl, why not? Here’s the link: 5sbetwin
Heard about hh55betcc on the grapevine. Gave it a shot and not disappointed. Got some lucky spins. Worth checking out if you’re looking for something new: hh55betcc