index record count difference

  • Hello,

    I have a table with approximately 1.300.000 records (Dynamics Navision 5.1), on the table are 21 indices. The problem is that a select count(*) without using an index delivers all records, the same statement with using an index delivers a count to 12 records less.

    After an index rebuild the result was o.k.

    Now some days later I have the same problem with 6 records less.

    Any idea what causes the problem?

    The server is a SQL 2008 R2 128GB Memory

  • Can you show us the exact queries you're running to get the counts, please?

    Thanks

    John

  • select COUNT(*) from [dbo].[AT101 Swietelsky Bau GmbH$Sachposten]with(index(0))

    where

    [Sachkontonr_]= '250020' and

    Buchungsdatum <= '2011-09-30'

    select COUNT(*) from [dbo].[AT101 Swietelsky Bau GmbH$Sachposten]with(index(7))

    where

    [Sachkontonr_]= '250020' and

    Buchungsdatum <= '2011-09-30'

    First selcect delivers: 1325748

    second: 1325742

  • Does the column(s) indexed in index ID 7 contain any NULLs? This would explain the difference, although it doesn't explain why it disappears after you rebuild the index.

    John

  • Sounds like you had some minor database corruption. Might be an idea to increase the frequency of checkDB for a while.

    Won't be nulls, because count(*) means count all rows regardless, not count non-null values.

    Gail Shaw
    Microsoft Certified Master: SQL Server, MVP, M.Sc (Comp Sci)
    SQL In The Wild: Discussions on DB performance with occasional diversions into recoverability

    We walk in the dark places no others will enter
    We stand on the bridge and no one may pass
  • I checked it - there are no Nulls

    the problem is, that the application (Navision) comes to different results, depending on what report was started. (with the profiler I saw the selects in the reports uses different indexes).

    the checktable (including indexes) reports no error.

    Werner

  • Wiesinger (11/16/2011)


    the checktable (including indexes) reports no error.

    No, it won't now, because the problem went away when you rebuilt the indexes.

    Indexes with a different number of rows to the table is a form of database corruption. It's a form that rebuilding the indexes does fix.

    Gail Shaw
    Microsoft Certified Master: SQL Server, MVP, M.Sc (Comp Sci)
    SQL In The Wild: Discussions on DB performance with occasional diversions into recoverability

    We walk in the dark places no others will enter
    We stand on the bridge and no one may pass
  • I executed the checktable befor rebuilding the index - there was no error log;

    the question is, what can cause this difference of rows in the index

  • One more time with feeling =>

    GilaMonster (11/16/2011)


    Wiesinger (11/16/2011)


    the checktable (including indexes) reports no error.

    No, it won't now, because the problem went away when you rebuilt the indexes.

    Indexes with a different number of rows to the table is a form of database corruption. It's a form that rebuilding the indexes does fix.

    When's the last time you ran a full checkdb?

  • every week on sunday

  • Do you have any errors in the logs about possible corruption?

  • no - there is absolute no indication for an error

  • Checking assumptions (since nothing else is making sense atm) =>

    What isolation level did you run this under?

    Was it under repeatable read and in the same batch?

    I have a few of those monster tables, and 6 rows inserted is always only 1 instant away.

  • the 6 records are old records (last year), we mentioned the error, because there where reports with different results.

    to find the problem I created a simple select with and without the use of an index. Last week we had the same problem with 12 records, so I rebuild all the indices of the table, and it worked. Today I have the same problem again with 6 other records.

    the error is repeateable with the simple select

    also the sys.dm_db_index_physical_stats reports different record counts

  • Right now the only thing that makes any sort of sense in my mind is readuncommited isolation level to explain this. Since it seems it's not corruption.

    Hopefully Gail has seen this before and knows about other options.

Viewing 15 posts - 1 through 15 (of 21 total)

You must be logged in to reply to this topic. Login to reply