I have a table in Oracle 10 with following structure
Create Table Bookmarks(
BOOKMARKID NUMBER(10,0) NOT NULL PRIMARY KEY,
URL VARCHAR2(4000 CHAR) NOT NULL UNIQUE
)
URL has a unique constraint set thus a unique index. There are about 1 million records in this table. I have to frequently check if a bookmark already exists in the table. I am issuing the following query
Select bookmarkid from Bookmarks where URL='<some url>'
The problem is that as the number of records have grown so has the performance gone down. Now It takes significantly longer to return the bookmark id specially when the query URL is long. In the Explain Plan the query does use Unique index on URL column. Any suggestions for improving response time?
You would typically use a hash index for this. In mssql I would create a persisted computed column that did like CRC(url). Then when you want to check for existance, you look up WHERE crc(‘some url’) = PersistedCrcColumn AND URL=’some url’
You have to include the original check with the crc check since you can occassionally get CRC collisions.
EDIT – changing my description above from ‘hash lookup’ to ‘hash index’ to avoid confusion. Some dbs have hash indexes as a first class index, I don’t believe oracle does (and I know mssql doesn’t). If it is not supported intrinsically, the above approach is how you implement it manually.