CExistValidator Excessive Query

Hey,

I see that the CExistValidator selects a field in order to determine if the specified piece of data exists in the given table.

Everyone knows a COUNT() is faster than selecting a field, so why are you not selecting a COUNT() and comparing it?

e.g.

SELECT COUNT(*) FROM user WHERE username = ‘Somename’

vs

SELECT id FROM user WHERE username = ‘Somename’

In the COUNT query, you simply check if the result is more than 0.

It is much, much faster than selecting a field for absolutely no reason.

I’ve looked at it very briefly and the problem (if there is a problem) is at CActiveRecord::exists.

There is EXISTS in SQL so maybe we should consider using it.

Please create an issue so we’ll not forget to analyze it: http://code.google.com/p/yii/issues/entry