title: SQLAlchemy low performance when use relationship
body: <p>I have SQLAlchemy models in my Flask application:</p>
  
  <pre><code>class User(db.Model):
      __tablename__ = 'users'
      id = db.Column(db.Integer, primary_key=True)
      photos = db.relationship('Photo', lazy='joined')
  
  class Photo(db.Model):
       __tablename__ = 'photos'
      id = db.Column(db.Integer, primary_key=True)
      user_id = db.Column(db.Integer, db.ForeignKey('users.id'))
      photo = db.Column(db.String(255))
  </code></pre>
  
  <p>When i query user i get user with his photos automatically. But i noticed if user has a lot of photos, query <code>u = User.query.get(1)</code> become very slow. I do the same but manually with <code>lazy='noload'</code> option</p>
  
  <pre><code>u = User.query.get(1)
  photos = Photo.query.filter_by(user_id == 1)
  </code></pre>
  
  <p>and on the same data it works faster in times. Where is problem, is sql join slow(don`t think so, because it start hang on 100-1kk photo objects, not so big data) or something wrong in the SQLAlchemy?</p>