tags:

views:

73

answers:

2

I have a database where one of the common queries is has a "where blobCol is null", I think that this is getting bad performance (as in a full table scan). I have no need to index the contents of the blobCol.

What indexes would improve this? Can an index be built on an expression (blobCol is not null) rather than just a column?

+1  A: 

Some databases allow indexes on expressions but a plain index should reduce the running time of your query significantly.

Robert Gamble
My concern is that a plain old index will use up a lot of resources indexing the data when all I want is if there is any data at all.
BCS
That's a fair point and, as I mentioned, some databases support indexes on expressions but I didn't know if yours was one of them as you didn't specify the database you were using.
Robert Gamble
+2  A: 

Yes, most DBMSs support it, for instance in PostgreSQL it is

CREATE INDEX notNullblob ON myTable (blobCol is not NULL);

It seems that the best you could do on SQL Server though is to create a computed column that, for example, will contain 1 if blob is null and 0 otherwise and create an index over that.

Vinko Vrsalovic
Does that work in MySQL?
mercutio
Not sure, but I think that it doesn't
Vinko Vrsalovic
it would seem that MySQL does not support this. OTOH an index with a prefix length of 1 does very well.
BCS