Yii Framework Forum: Optimization in Relational AR - Yii Framework Forum

Jump to content

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

Optimization in Relational AR Everything is working, but slowly. I've 20 tables, related each ot Rate Topic: -----

#1 User is offline   Nurbek 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 22
  • Joined: 26-August 09

Posted 15 April 2010 - 09:03 AM

Everything is working, but slowly. I have 20 tables, related each other.
I want to know

example:
3 tables: Grandfather, Father, Son

Getting a Son, sometimes I want get a Son with his Father and Grandfather,
sometimes I want get a Son only without Father and Grandfather.
I want to know

Is AR query return me object with relational objects only when I call that(Son->Father, Son->Father->Grandfather)
or it return me relational objects allways calling Son object?

I want to optimize my queries, want it works quickly, not slowly.
Is it posible, what do I have to do?
0

#2 User is offline   lgoss007 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 88
  • Joined: 01-October 09

Posted 15 April 2010 - 11:53 AM

How much do you know about SQL databases? What normal form are they in (3N, 5N, ...)? What database are you using (MySQL, Oracle, ...)? How many joins are you doing on one page?

In general what makes something slow in SQL is dependent on many variables so it's hard to say without more information. By default yii usually does lazy loading, meaning it will return you an object (Son for example).. then when you call Son->Father it will do another query to get the Father object. Again this all depends on how you query Son (also see: Relation Active Record and look at the section titled Relational Query Performance).

If you have a ton of joins on one page though, your best bet is to use DAO and manually do your query.
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