Hi Klemens,

The queries you're talking about come from Doctrine itself, and its
"lazy" behaviour. For example, if you do sth like "$albums =
Doctrine::getTable('Album')->findAll();", it will only take all the
rows from the table 'album'.
Now if you do sth like  '$artist_name = $album->Artist->name", it will
make a second request to retrieve the artist object. And if you have
15 albums, you will have 15 more queries.

To prevent that, you have to make complex queries with Left Joins,
Inner Joins... in order to retrieve all the data that is going to be
used in the script.

In this case, you would better do, for example, in your Album table:

class AlbumTable extends Doctrine_Table
{
  public function findAllWithJoins()
  {
    $q = $this->createQuery('a')->leftJoin('a.Artist art');
    return $q->fetchOne();
  }
}

Then you call Doctrine::getTable('Album')->findAllWithJoins();, and
you can do $album->Artist->name without making any extra query... 16
queries before  -> 1 query after.


Hoping I've well understood your question...


On 13 août, 16:10, klemens_u <[email protected]> wrote:
> Hi Eno,
>
> in my case there is quite complex logic involved including a lot of
> sfDoctrineForms etc.
> So it's not so easy anymore to trace at which pointDoctrineexecutes
> a query escpecially when a lot of relations are involved.
>
> There's also the second part of my question about the execution time
> of queries. If I remember correctly the web debug toolbar does show
> the execution time for each query when using propel.
>
> Has anyone used Doctrine_Connection_Profiler from within a symfony
> project?
>
> I'm sure I'm not the only one who is interested in this topic.
>
> Klemens
>
> On 13 Aug., 15:01, Eno <[email protected]> wrote:
>
> > On Thu, 13 Aug 2009, klemens_u wrote:
>
> > > bubbling this up...
>
> > Im guessing noone answered because its a bit of a strange question.
>
> > I mean, you wrote an action, so you should know where the queries are
> > coming from?!
>
> > > On Aug 12, 4:14 pm, klemens_u <[email protected]> wrote:
> > > > I'm using symfony 1.2.7 withDoctrine1.0 and I have an action which
> > > > produces far too much database queries.
>
> > > > What are your best practices to find out where the queries come from
> > > > and how much time they consume?
>
> > > > The web debug toolbar shows the total amount of queries and the query
> > > > itself but it contains no information on the time consumed nor the
> > > > origin of the query.
>
> > > > I've read about Doctrine_Connection_Profiler (http://www.doctrine-
> > > > project.org/documentation/manual/1_0/en/component-overview:profiler)
> > > > but I've found no information on how to use it within a symfony
> > > > project.
>
> > > > Thanks, Klemens

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"symfony users" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/symfony-users?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to