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

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.
0

#2 User is offline   samdark 

  • Having fun
  • Yii
  • Group: Yii Dev Team
  • Posts: 3,387
  • 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 1.1 Application Development Cookbook

Enjoying Yii? Star us at github: 1.1 and 2.0.
0

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