Getting Started with Adobe After Effects - Part 6: Motion Blur


Upload Image Close it
Select File

Browse by Tags · View All
SQL 3
COLUMNPROPERTY 1
OBJECT_NAME 1
OBJECT_ID 1
SysColumns 1
IF EXISTS 1
decimal 1
float 1
conversion error 1
implicit convertion 1

Archive · View All
March 2012 3
April 2012 2

Adam Tokarski's Blog

Example of use CHECKSUM

Mar 6 2012 12:00AM by Adam Tokarski   

That is just example for just learned post .

/* make sure you do not have actually real table with that name! */
IF OBJECT_ID('checksumsTable', 'U') IS NOT NULL
    DROP TABLE checksumsTable

CREATE TABLE checksumsTable(checksumsTableId int primary key IDENTITY(1, 1), someDescriptions varchar(MAX))

/* add table used as our own index */
ALTER TABLE checksumsTable ADD checkSumValue AS CHECKSUM(someDescriptions)

/* and index that index */
CREATE NONCLUSTERED INDEX ix_checksumsTable_checkSumValue ON checksumsTable(checkSumValue)

/* you could, always, create index on string column, but it works only for data < 900 bytes, as it is max length of key */
-- CREATE NONCLUSTERED INDEX ix_checksumsTable_someDescriptions ON checksumsTable(someDescriptions)


/* fill our newly created table with some random datas */
INSERT INTO checksumsTable(someDescriptions)
SELECT 
(
    /*	I assume that it is not perfect method, but it actually works. And it is fast. 
        Table 'Numbers' is common Tally Table */
    SELECT CHAR(CAST(NEWID() AS BINARY(1))*N.n % 25 + 65) AS [text()] 
    FROM Numbers WHERE n < 8000
    FOR XML PATH ('')
) [xx]
FROM Numbers N WHERE n < 1001
And that most valuable part is: When we compare it directly:
SELECT #checksumsTableId FROM #checksumsTable WHERE 'AAFPPFFUFPFPUFPAFAUPFKKAFAKUFAAUK(...cut!)' = someDescriptions
vs using CHECKSUMS:
SELECT #checksumsTableId FROM #checksumsTable WHERE CHECKSUM('AAFPPFFUFPFPUFPAFAUPFKKAFAKUFAAUK(...cut!)') = checkSumValue
As you can see, using checksum improves looking for data.

Without it, I had in my case 1005 logical reads, while with CHECKSUM, it was 2 logical reads. However - you can say - we could use classic index. Yes, but not for so long strings.
If, even, you've created index for no longer than VARCHAR(900), then, that index would be much bigger and heavier, I think.
And, anyway, its just an example.

Tags: CHECKSUM, CHECKSUM_AGG, HASH


Adam Tokarski
58 · 3% · 1021
3
 
0
Lifesaver
 
0
Refreshed
 
 
0
Incorrect



Submit

2  Comments  

  • Don't forget that CHECKSUM can cause collisions. To solve this, use both predicate.

    SELECT #checksumsTableId 
    FROM   #checksumsTable 
    WHERE  CHECKSUM('AAFPPFFUFPFPUFPAFAUPFKKAFAKUFAAUK(...cut!)') = checkSumValue
      AND  'AAFPPFFUFPFPUFPAFAUPFKKAFAKUFAAUK(...cut!)' = someDescriptions
    

    I tested it over a 13 millions email table

    A +

    commented on Apr 23 2012 4:42PM
    Frédéric Brouard
    1310 · 0% · 17
  • @Frédéric Brouard: thanks for checking this checksum.
    Does 'can cause collisions' mean that it may be not unique? Did you found these collisions during your testing?

    commented on Apr 24 2012 1:33AM
    Adam Tokarski
    58 · 3% · 1021

Your Comment


Sign Up or Login to post a comment.

"Example of use CHECKSUM" rated 5 out of 5 by 3 readers
Example of use CHECKSUM , 5.0 out of 5 based on 3 ratings
    Copyright © Rivera Informatic Private Ltd Contact us      Privacy Policy      Terms of use      Report Abuse      Advertising      [ZULU1097]