Yii Framework Forum: CExistValidator Excessive Query - Yii Framework Forum

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

CExistValidator Excessive Query Rate Topic: -----

#1 User is offline   JmZ 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 3
  • Joined: 22-June 10

Posted 23 June 2010 - 12:31 PM


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?

SELECT COUNT(*) FROM user WHERE username = 'Somename'
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.

#2 User is offline   samdark 

  • Having fun
  • Yii
  • Group: Yii Dev Team
  • Posts: 5,225
  • Joined: 17-January 09
  • Location:Russia

Posted 23 June 2010 - 02:36 PM

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.c...ii/issues/entry
Yii 2.0 Development Cookbook

Enjoying Yii? Star us at github

Support me so I can work more on Yii: https://www.patreon.com/samdark

Share this topic:

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users